Commit 2cab3a58 authored by Trio Saputra's avatar Trio Saputra

new updated

parent 7629187c
...@@ -4,22 +4,16 @@ import androidx.appcompat.app.AppCompatActivity; ...@@ -4,22 +4,16 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.loader.content.CursorLoader;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.example.yourcashiertest.R; import com.example.yourcashiertest.R;
import com.example.yourcashiertest.databinding.ActivityProductBinding; import com.example.yourcashiertest.databinding.ActivityProductBinding;
...@@ -38,7 +32,6 @@ public class ProductActivity extends AppCompatActivity{ ...@@ -38,7 +32,6 @@ public class ProductActivity extends AppCompatActivity{
private static final int REQUEST_IMAGE_CAPTURE = 1; private static final int REQUEST_IMAGE_CAPTURE = 1;
private File file; private File file;
private ProductViewModel viewModel; private ProductViewModel viewModel;
Uri selectedImageUri;
@Override @Override
...@@ -49,6 +42,7 @@ public class ProductActivity extends AppCompatActivity{ ...@@ -49,6 +42,7 @@ public class ProductActivity extends AppCompatActivity{
binding = DataBindingUtil.setContentView(this, R.layout.activity_product); binding = DataBindingUtil.setContentView(this, R.layout.activity_product);
Product product = getIntent().getParcelableExtra(MainActivity.DATA_PRODUCT); Product product = getIntent().getParcelableExtra(MainActivity.DATA_PRODUCT);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
...@@ -82,9 +76,6 @@ public class ProductActivity extends AppCompatActivity{ ...@@ -82,9 +76,6 @@ public class ProductActivity extends AppCompatActivity{
if (file != null){ if (file != null){
fixProduct.setPhoto(file.getAbsolutePath()); fixProduct.setPhoto(file.getAbsolutePath());
}else {
fixProduct.setPhoto("");
} }
fixProduct.setName(binding.etProduct.getText().toString()); fixProduct.setName(binding.etProduct.getText().toString());
...@@ -108,21 +99,6 @@ public class ProductActivity extends AppCompatActivity{ ...@@ -108,21 +99,6 @@ public class ProductActivity extends AppCompatActivity{
binding.setViewModel(viewModel); binding.setViewModel(viewModel);
} }
private void openFile(){
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 100);
}
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;
}
private void takePhoto() { private void takePhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
...@@ -186,13 +162,6 @@ public class ProductActivity extends AppCompatActivity{ ...@@ -186,13 +162,6 @@ public class ProductActivity extends AppCompatActivity{
} }
} }
public void getPhoto(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "select a picture"), REQUEST_IMAGE_CAPTURE);
}
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable
name="photo"
type="String" />
<variable <variable
name="viewModel" name="viewModel"
type="com.example.yourcashiertest.viewmodels.ProductViewModel" /> type="com.example.yourcashiertest.viewmodels.ProductViewModel" />
...@@ -18,7 +15,7 @@ ...@@ -18,7 +15,7 @@
android:background="@color/white" android:background="@color/white"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/tvHeadProduct" android:id="@+id/tvHeadProduct"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -42,11 +39,11 @@ ...@@ -42,11 +39,11 @@
<ImageView <ImageView
android:id="@+id/ivProduct" android:id="@+id/ivProduct"
android:layout_width="146dp" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:src="@drawable/unnamed" android:src="@drawable/unnamed"
app:file="@{photo}" /> app:file="@{viewModel.product.photo}"/>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
...@@ -169,4 +166,4 @@ ...@@ -169,4 +166,4 @@
</RelativeLayout> </RelativeLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>
</layout> </layout>
\ 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