Implement UI Info Toko

This commit is contained in:
riz081 2025-07-04 18:47:44 +07:00
parent c18fd2d831
commit 671b585fe5
8 changed files with 293 additions and 94 deletions

View File

@ -39,6 +39,8 @@ public class LoginActivity extends AppCompatActivity {
private ProgressBar progressBar;
private ExecutorService executor;
private String currentPassword;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
@ -119,6 +121,8 @@ public class LoginActivity extends AppCompatActivity {
private void performLogin(String identifier, String password) {
setLoadingState(true);
currentPassword = password;
executor.execute(() -> {
try {
// Create JSON payload
@ -193,7 +197,14 @@ public class LoginActivity extends AppCompatActivity {
JSONObject userData = result.getJSONObject("user");
// Save login data
saveLoginData(token, userData.toString());
// saveLoginData(token, userData.toString());
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(KEY_TOKEN, token);
editor.putString(KEY_USER_DATA, userData.toString());
editor.putBoolean(KEY_IS_LOGGED_IN, true);
editor.putString("current_password", currentPassword);
editor.apply();
Toast.makeText(this, "Login berhasil! " + message, Toast.LENGTH_SHORT).show();

View File

@ -1,10 +1,13 @@
package com.example.bdkipoc.infotoko;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewParent;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
@ -18,6 +21,8 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import android.text.method.PasswordTransformationMethod;
import org.json.JSONException;
import org.json.JSONObject;
@ -40,11 +45,12 @@ public class InfoTokoActivity extends AppCompatActivity {
private TextInputEditText etAddress;
private MaterialButton btnUpdate;
private ImageView btnBack;
private LinearLayout backNavigation; // Changed from ImageView to LinearLayout
// Data
private String authToken;
private JSONObject userData;
private String userPassword; // Add password storage
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -75,7 +81,15 @@ public class InfoTokoActivity extends AppCompatActivity {
tvStoreName = findViewById(R.id.tv_store_name);
tvMerchantId = findViewById(R.id.tv_merchant_id);
tvTerminalId = findViewById(R.id.tv_terminal_id);
btnBack = findViewById(R.id.btn_back);
// Find the back navigation from the included layout
backNavigation = findViewById(R.id.back_navigation);
// Optionally, you can also update the title in the appbar
TextView appbarTitle = findViewById(R.id.appbarTitle);
if (appbarTitle != null) {
appbarTitle.setText("Kembali");
}
// Account Information
etEmail = findViewById(R.id.et_email);
@ -114,20 +128,59 @@ public class InfoTokoActivity extends AppCompatActivity {
userData = LoginActivity.getUserDataAsJson(this);
}
// Get saved password from SharedPreferences
SharedPreferences prefs = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
userPassword = prefs.getString("current_password", ""); // Fix: use correct key
Log.d(TAG, "Loaded auth token: " + (authToken != null ? "" : ""));
Log.d(TAG, "Loaded user data: " + (userData != null ? "" : ""));
Log.d(TAG, "Loaded password: " + (!userPassword.isEmpty() ? "" : ""));
}
private void setupListeners() {
// Back button
if (btnBack != null) {
btnBack.setOnClickListener(v -> finish());
// Back button - now using the LinearLayout
if (backNavigation != null) {
backNavigation.setOnClickListener(v -> {
Log.d(TAG, "Back button clicked");
finish();
});
} else {
Log.e(TAG, "Back navigation not found!");
}
// Update button
if (btnUpdate != null) {
btnUpdate.setOnClickListener(v -> updateStoreInfo());
}
// Password toggle listener
setupPasswordToggle();
}
private void setupPasswordToggle() {
ViewParent passwordParentView = etPassword.getParent().getParent();
if (passwordParentView instanceof TextInputLayout) {
TextInputLayout passwordLayout = (TextInputLayout) passwordParentView;
// Set initial state to visible
etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
passwordLayout.setEndIconOnClickListener(v -> {
// Toggle password visibility
if (etPassword.getTransformationMethod() == null) {
// Hide password
etPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordLayout.setEndIconDrawable(R.drawable.ic_visibility_off); // Set your eye-off icon
} else {
// Show password
etPassword.setTransformationMethod(null);
passwordLayout.setEndIconDrawable(R.drawable.ic_visibility); // Set your eye icon
}
// Move cursor to end
etPassword.setSelection(etPassword.getText().length());
});
}
}
private void displayStoreInfo() {
@ -150,9 +203,33 @@ public class InfoTokoActivity extends AppCompatActivity {
etEmail.setText("Email tidak tersedia");
}
// Password - show masked placeholder (we don't store actual password)
etPassword.setText("••••••••");
etPassword.setEnabled(false); // Disable editing for security
// Password - show actual password from SharedPreferences (VISIBLE by default)
if (!userPassword.isEmpty()) {
etPassword.setText(userPassword);
// Start with password visible
etPassword.setTransformationMethod(null);
// Refresh the eye icon state
ViewParent passwordParentView = etPassword.getParent().getParent();
if (passwordParentView instanceof TextInputLayout) {
((TextInputLayout) passwordParentView).setEndIconDrawable(R.drawable.ic_visibility);
}
} else {
etPassword.setText("");
}
etPassword.setEnabled(true); // Enable for display with toggle
// Update the eye icon to show "hide" state initially
ViewParent passwordParentView = etPassword.getParent().getParent();
if (passwordParentView instanceof TextInputLayout) {
TextInputLayout passwordLayout = (TextInputLayout) passwordParentView;
passwordLayout.setPasswordVisibilityToggleEnabled(true);
// Force refresh the toggle icon
passwordLayout.refreshDrawableState();
}
// Debug log
Log.d(TAG, "Password field text: " + etPassword.getText().toString());
Log.d(TAG, "Password field length: " + etPassword.getText().length());
// Nama Pemilik - from API response
String ownerName = userData.optString("name", "");
@ -210,7 +287,10 @@ public class InfoTokoActivity extends AppCompatActivity {
ViewParent addressContainer = etAddress.getParent();
if (addressContainer != null && addressContainer instanceof View) {
((View) addressContainer).setVisibility(View.GONE);
}
}
// Update the section title to be more accurate
// Note: You'll need to add an ID to the section title TextView in the XML
}
private void updateStoreInfo() {
@ -233,6 +313,13 @@ public class InfoTokoActivity extends AppCompatActivity {
// Show success message
Toast.makeText(this, "Informasi akun berhasil diperbarui", Toast.LENGTH_SHORT).show();
// If password was changed, inform user
String currentPasswordText = etPassword.getText().toString();
if (!currentPasswordText.isEmpty() && !currentPasswordText.equals(userPassword)) {
Toast.makeText(this, "Password berhasil diperbarui", Toast.LENGTH_SHORT).show();
userPassword = currentPasswordText; // Update local variable
}
// Reset button state
btnUpdate.setEnabled(true);
btnUpdate.setText("Perbarui Informasi Toko");
@ -280,11 +367,20 @@ public class InfoTokoActivity extends AppCompatActivity {
return false;
}
// Check password if changed
String password = etPassword.getText().toString();
if (!password.isEmpty() && password.length() < 6) {
etPassword.setError("Password minimal 6 karakter");
etPassword.requestFocus();
return false;
}
return true;
}
private void saveUpdatedData() {
// In a real app, this would update the user data in SharedPreferences
// and call an API to update the server
try {
JSONObject updatedData = new JSONObject();
updatedData.put("email", etEmail.getText().toString().trim());
@ -299,8 +395,22 @@ public class InfoTokoActivity extends AppCompatActivity {
// Add other fields as needed
}
// Save updated password to SharedPreferences
String newPassword = etPassword.getText().toString();
if (!newPassword.isEmpty() && !newPassword.equals(userPassword)) {
SharedPreferences prefs = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
prefs.edit().putString("current_password", newPassword).apply(); // Fix: use correct key
Log.d(TAG, "Password updated in SharedPreferences");
}
Log.d(TAG, "Updated data: " + updatedData.toString());
// In real app, you would:
// 1. Call API to update user data
// 2. On success, update SharedPreferences:
// SharedPreferences prefs = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
// prefs.edit().putString("user_data", updatedData.toString()).apply();
} catch (JSONException e) {
Log.e(TAG, "Error creating updated data: " + e.getMessage());
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/black"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/black"
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!-- Semi-transparent color similar to #CCB2B24D -->
<solid android:color="#30FFFFFF" />
</shape>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#DE0701" />
<corners
android:bottomLeftRadius="48dp"
android:bottomRightRadius="48dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>

View File

@ -5,37 +5,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#E53935"
android:background="#FFFFFF"
tools:context=".InfoTokoActivity">
<!-- Header with back button -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:paddingHorizontal="16dp">
<ImageView
android:id="@+id/btn_back"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_back"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="Back"
app:tint="@android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Info Toko"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<!-- Custom AppBar -->
<include layout="@layout/component_appbar_small" />
<ScrollView
android:layout_width="match_parent"
@ -48,83 +22,141 @@
android:orientation="vertical">
<!-- Red background section with logo and store info -->
<LinearLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="24dp"
android:background="#E53935">
android:layout_height="wrap_content">
<!-- Logo -->
<androidx.cardview.widget.CardView
<!-- Background with rounded bottom corners -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_bottom_background" />
<!-- Decorative Ovals -->
<!-- Oval 1 - Top Left Large -->
<View
android:layout_width="120dp"
android:layout_height="120dp"
app:cardCornerRadius="60dp"
app:cardElevation="4dp">
android:layout_marginStart="-40dp"
android:layout_marginTop="-30dp"
android:background="@drawable/oval_blur_decoration"
android:rotation="15" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_logo_icon"
android:scaleType="centerCrop"
android:contentDescription="Logo Pak Eko" />
<!-- Oval 2 - Top Right Medium -->
<View
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginStart="280dp"
android:layout_marginTop="13dp"
android:background="@drawable/oval_blur_decoration"
android:rotation="-20" />
</androidx.cardview.widget.CardView>
<!-- Oval 3 - Bottom Left Small -->
<View
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="54dp"
android:layout_marginTop="180dp"
android:background="@drawable/oval_blur_decoration"
android:rotation="45" />
<!-- Store Name -->
<TextView
android:id="@+id/tv_store_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="TOKO KLONTONG PAK EKO"
android:textColor="@android:color/white"
android:textSize="18sp"
android:textStyle="bold" />
<!-- Oval 4 - Bottom Right Medium -->
<View
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_marginStart="250dp"
android:layout_marginTop="160dp"
android:background="@drawable/oval_blur_decoration"
android:rotation="0" />
<!-- MID and TID -->
<!-- Oval 5 - Center Left Small -->
<View
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginStart="20dp"
android:layout_marginTop="90dp"
android:background="@drawable/oval_blur_decoration"
android:rotation="30" />
<!-- Main Content -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp">
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingTop="16dp"
android:paddingBottom="40dp">
<!-- Logo -->
<androidx.cardview.widget.CardView
android:layout_width="120dp"
android:layout_height="120dp"
app:cardCornerRadius="60dp"
app:cardElevation="4dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_logo_toko"
android:scaleType="centerCrop"
android:contentDescription="Logo Pak Eko" />
</androidx.cardview.widget.CardView>
<!-- Store Name -->
<TextView
android:id="@+id/tv_merchant_id"
android:id="@+id/tv_store_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MID: 12345678901"
android:layout_marginTop="16dp"
android:text="TOKO KLONTONG PAK EKO"
android:textColor="@android:color/white"
android:textSize="14sp" />
android:textSize="18sp"
android:textStyle="bold" />
<TextView
<!-- MID and TID -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:text="|"
android:textColor="@android:color/white"
android:textSize="14sp" />
android:orientation="horizontal"
android:layout_marginTop="8dp">
<TextView
android:id="@+id/tv_terminal_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TID: 12345678901"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_merchant_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MID: 12345678901"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:text="|"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_terminal_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TID: 12345678901"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<!-- White card with store information -->
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="-16dp"
android:layout_marginTop="-36dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="12dp"
app:cardElevation="4dp">
@ -168,13 +200,14 @@
android:layout_marginTop="12dp"
android:hint="Kata Sandi"
app:passwordToggleEnabled="true"
app:endIconMode="password_toggle"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:inputType="text"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
@ -308,9 +341,13 @@
android:text="Perbarui Informasi Toko"
android:textAllCaps="false"
android:textSize="16sp"
android:textColor="@android:color/black"
app:cornerRadius="28dp"
android:backgroundTint="@android:color/white" />
android:textStyle="bold"
android:textColor="#DE0701"
android:backgroundTint="@android:color/white"
app:cornerRadius="8dp"
app:strokeColor="#DE0701"
app:strokeWidth="2dp" />
</LinearLayout>