Commit 4891bf7a authored by Muhammad Suryono's avatar Muhammad Suryono

pdate form

parent 2c5e12f3
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<DBN-PSQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -3,6 +3,12 @@
package="com.yono.messeripos">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:allowBackup="true"
......@@ -31,6 +37,16 @@
android:theme="@style/AppTheme.appbar" />
<activity android:name=".FormProductActivity" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.android.messer"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/path"/>
</provider>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
......
package com.yono.messeripos;
import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.PersistableBundle;
import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.databinding.DataBindingUtil;
import com.google.android.material.appbar.MaterialToolbar;
import com.yono.messeripos.databinding.FormProductBinding;
import com.yono.messeripos.models.ProductModels;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FormProductActivity extends AppCompatActivity {
FormProductBinding binding;
ProductModels productModels;
File file;
private static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int REQUEST_PERMISSIONS = 448;
private boolean isUpdate = false;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_product);
binding = DataBindingUtil.setContentView(this, R.layout.form_product);
binding.btnAdd.setText("Add New Prooduct");
productModels = new ProductModels();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
MaterialToolbar toolbars = findViewById(R.id.topAppBarForm);
setSupportActionBar(toolbars);
......@@ -20,5 +58,93 @@ public class FormProductActivity extends AppCompatActivity {
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Add Product");
toolbars.setNavigationOnClickListener(view -> onBackPressed());
binding.cvProduct.setOnClickListener(view -> takePhoto());
binding.btnAdd.setOnClickListener(view -> saveProduct());
}
private void saveProduct(){
productModels.setProductName(binding.etName.getText().toString());
productModels.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString()));
productModels.setStockProduct(Integer.parseInt(binding.etStock.getText().toString()));
Toast.makeText(this, productModels.getImageProduct()+" "+productModels.getProductName(), Toast.LENGTH_LONG).show();
}
private void openFile(){
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 100);
}
private File createImageFile() {
try {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File image = File.createTempFile(
"MESSER_" + timeStamp + "_",
".jpg",
getExternalFilesDir(Environment.DIRECTORY_PICTURES)
);
file = image;
return image;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
private void takePhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = createImageFile();
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.messer",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == 100 && resultCode == RESULT_OK && data != null) {
// Uri selectedImage = data.getData();
//
// Log.d("Get filepath photo", "" + getRealPathFromURI(selectedImage));
// binding.setPhoto(getRealPathFromURI(selectedImage));
// }
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Log.d("Get filepath photo", "" + file.getName());
binding.setPhoto(file.getAbsolutePath());
productModels.setImageProduct(file.getName());
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSIONS && grantResults.length != permissions.length) {
requestPermissions(permissions, REQUEST_PERMISSIONS);
}
}
private String getRealPathFromURI(Uri contentUri) {
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String result = cursor.getString(column_index);
cursor.close();
return result;
}
}
......@@ -5,11 +5,13 @@ import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
......@@ -50,6 +52,7 @@ public class MainActivity extends AppCompatActivity {
CategoryAdapter categoryAdapter;
ProductAdapter productAdapter;
CartAdapter cartAdapter;
TextView txtBadge;
public static Boolean status_update = false;
MainViewModelsCart mainViewModelsCart;
......@@ -64,7 +67,7 @@ public class MainActivity extends AppCompatActivity {
categoryAdapter = new CategoryAdapter();
productAdapter = new ProductAdapter();
mainViewModelsCart = new ViewModelProvider(MainActivity.this).get(MainViewModelsCart.class);
cartAdapter = new CartAdapter();
// cartAdapter = new CartAdapter();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
......@@ -83,13 +86,6 @@ public class MainActivity extends AppCompatActivity {
status_update = true;
binding.rvCategory.setVisibility(View.GONE);
productAdapter.notifyDataSetChanged();
mainViewModelsCart.getCartProduct().observe(MainActivity.this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
String js = new Gson().toJson(productCartModels);
Log.d("from cart", "Response " + js);
}
});
}else if (id == R.id.create) {
startActivity(new Intent(getApplicationContext(), FormProductActivity.class));
}
......@@ -139,4 +135,16 @@ public class MainActivity extends AppCompatActivity {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.home, menu);
final MenuItem menuItem = menu.findItem(R.id.menu_cart);
View actionView = menuItem.getActionView();
txtBadge = actionView.findViewById(R.id.cart_badge);
return true;
}
}
\ No newline at end of file
......@@ -7,11 +7,23 @@ import com.yono.messeripos.response.DataResponse;
import java.util.List;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.Part;
public interface ProductService {
@GET(ApiHelper.VERSI_API_1+"products-join")
Call<DataResponse<List<ProductModels<CategoryModels>>>> getProducts();
@Multipart
@GET(ApiHelper.VERSI_API_1+"products")
Call<DataResponse<ProductModels>> postProduct(
@Part("image\"; filename=\"messer_file.jpg\"")RequestBody image,
@Part RequestBody name,
@Part RequestBody price,
@Part RequestBody stock,
@Part RequestBody category_id
);
}
package com.yono.messeripos.models;
import android.text.TextUtils;
import android.widget.ImageView;
import androidx.databinding.BindingAdapter;
......@@ -10,6 +11,8 @@ import com.google.gson.annotations.SerializedName;
import com.yono.messeripos.R;
import com.yono.messeripos.api.ApiHelper;
import java.io.File;
public class ProductModels<T> {
@SerializedName("id")
private int idProduct;
......@@ -88,4 +91,15 @@ public class ProductModels<T> {
.into(view);
}
}
@BindingAdapter("path")
public static void setPathImage(ImageView view, String path) {
if (TextUtils.isEmpty(path)) view.setImageResource(R.mipmap.ic_launcher_round);
else {
File file = new File(path);
if (file.exists()) Glide.with(view).load(file).into(view);
else view.setImageResource(R.mipmap.ic_launcher_round);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@android:color/holo_red_dark"/>
<stroke android:color="@android:color/white" android:width="1dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
style="?attr/actionButtonStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:focusable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_baseline_shopping_cart_24"/>
<TextView
android:id="@+id/cart_badge"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right|end|top"
android:layout_marginEnd="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="3dp"
android:background="@drawable/basge_background"
android:gravity="center"
android:padding="3dp"
android:textColor="@android:color/white"
android:text="0"
android:textSize="10sp"/>
</FrameLayout>
\ No newline at end of file
This diff is collapsed.
......@@ -3,9 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_cart"
android:orderInCategory="100"
app:showAsAction="ifRoom"
app:showAsAction="always"
android:icon="@drawable/ic_baseline_shopping_cart_24"
android:actionLayout="@layout/custome_action_badge"
android:title="Cart" />
<item
......
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path
name="photos"
path="/" />
</paths>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment