Created
December 31, 2025 17:23
-
-
Save sajjadyousefnia/94e6a5a744eea209be18798a0cdd40b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.asantech.asanpay.product; | |
| import android.app.ProgressDialog; | |
| import android.content.Intent; | |
| import android.graphics.Color; | |
| import android.net.Uri; | |
| import android.os.Bundle; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.EditText; | |
| import android.widget.ImageButton; | |
| import android.widget.TextView; | |
| import android.widget.Toast; | |
| import androidx.appcompat.app.AppCompatActivity; | |
| import com.android.volley.DefaultRetryPolicy; | |
| import com.android.volley.Request; | |
| import com.android.volley.RequestQueue; | |
| import com.android.volley.toolbox.StringRequest; | |
| import com.android.volley.toolbox.Volley; | |
| import com.asantech.asanpay.setting.Globals; | |
| import com.asantech.asanpay.R; | |
| import com.asantech.asanpay.user.UserObject; | |
| import com.google.android.material.bottomsheet.BottomSheetDialog; | |
| import com.squareup.picasso.Picasso; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import java.text.DecimalFormat; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| import java.util.Objects; | |
| import de.hdodenhof.circleimageview.CircleImageView; | |
| public class ProductActivity extends AppCompatActivity { | |
| private int pneedmob, pneedserial, pneedlink; | |
| private EditText order_mobile_edt, order_serial_edt,order_link_edt, order_usrdsc_edt, orderOtherUsername; | |
| private ProgressDialog progressDialog; | |
| private boolean isOther = false; | |
| private String otherUserId = ""; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_product); | |
| Objects.requireNonNull(getSupportActionBar()).hide(); | |
| progressDialog = new ProgressDialog(this); | |
| progressDialog.setCancelable(false); | |
| progressDialog.setMessage(getString(R.string.wait)); | |
| findViewById(R.id.back_ibtn).setOnClickListener(v -> finish()); | |
| findViewById(R.id.balance_btn).setOnClickListener(v -> ShowAdbalanceBottomSheet()); | |
| Bundle bundle = getIntent().getExtras(); | |
| String currency = bundle.getString("currency"); | |
| String balance = bundle.getString("balance"); | |
| int pid = bundle.getInt("pid"); | |
| String ptitle = bundle.getString("ptitle"); | |
| String power_price = bundle.getString("power_price"); | |
| String pname = bundle.getString("pname"); | |
| String pdsc = bundle.getString("pdsc"); | |
| String pimg = bundle.getString("pimg"); | |
| String pprice = bundle.getString("pprice"); | |
| String pprice_show = bundle.getString("pprice_show"); | |
| pneedmob = bundle.getInt("pneedmob"); | |
| pneedserial = bundle.getInt("pneedserial"); | |
| pneedlink = bundle.getInt("pneedlink"); | |
| String user_mobile = bundle.getString("user_mobile", ""); | |
| isOther = bundle.getBoolean("other", false); | |
| CircleImageView product_img = findViewById(R.id.product_img); | |
| TextView product_title = findViewById(R.id.product_title); | |
| TextView product_detail = findViewById(R.id.product_detail); | |
| TextView product_description = findViewById(R.id.product_description); | |
| TextView product_price = findViewById(R.id.product_price); | |
| TextView product_price_show = findViewById(R.id.product_price_show); | |
| TextView balance_tv = findViewById(R.id.balance_tv); | |
| ViewGroup order_mobile_lyt = findViewById(R.id.order_mobile_lyt); | |
| ViewGroup order_serial_lyt = findViewById(R.id.order_serial_lyt); | |
| ViewGroup order_link_lyt = findViewById(R.id.order_link_lyt); | |
| order_mobile_edt = findViewById(R.id.order_mobile_edt); | |
| order_serial_edt = findViewById(R.id.order_serial_edt); | |
| order_link_edt = findViewById(R.id.order_link_edt); | |
| order_usrdsc_edt = findViewById(R.id.order_usrdsc_edt); | |
| orderOtherUsername = findViewById(R.id.otherEdt); | |
| order_mobile_edt.setText(user_mobile); | |
| if (isOther) { | |
| findViewById(R.id.tvOther).setVisibility(View.VISIBLE); | |
| findViewById(R.id.otherlayout).setVisibility(View.VISIBLE); | |
| } else { | |
| findViewById(R.id.tvOther).setVisibility(View.GONE); | |
| findViewById(R.id.otherlayout).setVisibility(View.GONE); | |
| } | |
| if (pneedmob == 1) { | |
| order_mobile_lyt.setVisibility(View.VISIBLE); | |
| } else { | |
| order_mobile_lyt.setVisibility(View.GONE); | |
| } | |
| if (pneedserial == 1) { | |
| order_serial_lyt.setVisibility(View.VISIBLE); | |
| } else { | |
| order_serial_lyt.setVisibility(View.GONE); | |
| } | |
| if (pneedlink == 1) { | |
| order_link_lyt.setVisibility(View.VISIBLE); | |
| } else { | |
| order_link_lyt.setVisibility(View.GONE); | |
| } | |
| Picasso.get().load(Globals.global_link + "images/" + pimg).into(product_img); | |
| product_title.setText(ptitle); | |
| product_detail.setText(pname); | |
| product_description.setText(pdsc); | |
| /* product_price.setText(pprice); | |
| switch (currency) { | |
| case "usd": { | |
| balance_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.usd_crncy))); | |
| product_price.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(pprice)), getString(R.string.usd_crncy))); | |
| } | |
| break; | |
| case "afg": { | |
| balance_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.afg_crncy))); | |
| product_price.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(pprice)), getString(R.string.afg_crncy))); | |
| } | |
| break; | |
| case "irt": { | |
| balance_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.irt_crncy))); | |
| product_price.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(pprice)), getString(R.string.irt_crncy))); | |
| } | |
| break; | |
| }*/ | |
| String priceHolder = getString(R.string.usd_crncy); | |
| switch (currency) { | |
| case "usd": { | |
| priceHolder = getString(R.string.usd_crncy); | |
| // holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(prdcts_price.getDouble(position)), context.getString(R.string.usd_crncy))); | |
| break; | |
| } | |
| case "afg": { | |
| priceHolder = getString(R.string.afg_crncy); | |
| //holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(prdcts_price.getDouble(position)), context.getString(R.string.afg_crncy))); | |
| break; | |
| } | |
| case "irt": { | |
| priceHolder = getString(R.string.irt_crncy); | |
| //holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(prdcts_price.getDouble(position)), context.getString(R.string.irt_crncy))); | |
| break; | |
| } | |
| case "lir": { | |
| priceHolder = getString(R.string.lir_crncy); | |
| //holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(prdcts_price.getDouble(position)), context.getString(R.string.irt_crncy))); | |
| break; | |
| } | |
| } | |
| balance_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), priceHolder)); | |
| product_price.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(pprice)), priceHolder)); | |
| product_price_show.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(pprice_show)), priceHolder)); | |
| boolean balanceMorethanPrice; | |
| if (Double.parseDouble(pprice) > Double.parseDouble(balance)) { | |
| balance_tv.setTextColor(Color.RED); | |
| balanceMorethanPrice = false; | |
| } else { | |
| balance_tv.setTextColor(getResources().getColor(R.color.my_green_dark)); | |
| balanceMorethanPrice = true; | |
| } | |
| findViewById(R.id.buy_btn).setOnClickListener(view -> { | |
| String order_mobile = order_mobile_edt.getText().toString().trim(); | |
| String order_serial = order_serial_edt.getText().toString().trim(); | |
| String order_link = order_link_edt.getText().toString().trim(); | |
| String order_usrdsc = order_usrdsc_edt.getText().toString().trim(); | |
| String other_username = orderOtherUsername.getText().toString().trim(); | |
| if (balanceMorethanPrice) { | |
| if (IsValidInputs(order_mobile, order_serial, order_link)) { | |
| View view_sheet = getLayoutInflater().inflate(R.layout.bottomsheet_buyproduct, null); | |
| BottomSheetDialog dialog = new BottomSheetDialog(this); | |
| EditText pin_edt = view_sheet.findViewById(R.id.pin_edt); | |
| ImageButton cancel_btn = view_sheet.findViewById(R.id.cancel_btn); | |
| cancel_btn.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View view) { | |
| dialog.dismiss(); | |
| } | |
| }); | |
| view_sheet.findViewById(R.id.confirm_btn).setOnClickListener(v -> { | |
| if (pin_edt.getText().length() == 4) { | |
| if (isOther) { | |
| if (other_username.isEmpty()) { | |
| Toast.makeText(this, getString(R.string.incorrect_username), Toast.LENGTH_SHORT).show(); | |
| } else { | |
| getUserFromId(other_username, new UserSearch() { | |
| @Override | |
| public void OnSearch(UserObject user) { | |
| otherUserId = user.userId; | |
| if (user.UserStatus == 1) { | |
| checkPinAndSetOrder(dialog, pin_edt, pid, order_mobile, order_serial, order_link, order_usrdsc); | |
| } else { | |
| Toast.makeText(ProductActivity.this, getString(R.string.notActive), Toast.LENGTH_SHORT).show(); | |
| } | |
| } | |
| @Override | |
| public void OnNotFound() { | |
| Toast.makeText(ProductActivity.this, getString(R.string.notfound), Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| } | |
| } else { | |
| checkPinAndSetOrder(dialog, pin_edt, pid, order_mobile, order_serial, order_link, order_usrdsc); | |
| } | |
| } else { | |
| Toast.makeText(this, getString(R.string.incorrectPin), Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| dialog.setContentView(view_sheet); | |
| dialog.show(); | |
| } | |
| } else { | |
| Toast.makeText(this, R.string.insufficient_balance, Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| } | |
| interface UserSearch { | |
| void OnSearch(UserObject user); | |
| void OnNotFound(); | |
| } | |
| private void getUserFromId(String username, UserSearch search) { | |
| progressDialog.show(); | |
| RequestQueue requestQueue = Volley.newRequestQueue(this); | |
| String req_url = Globals.global_link + "user_searchuser.php"; | |
| StringRequest stringRequest = new StringRequest(Request.Method.POST, req_url, response -> { | |
| progressDialog.dismiss(); | |
| try { | |
| JSONObject jresponse = new JSONObject(response); | |
| boolean status = jresponse.getBoolean("status"); | |
| String message = jresponse.getString("message"); | |
| if (status) { | |
| JSONObject data = jresponse.getJSONObject("data"); | |
| search.OnSearch(new UserObject(data.getInt("id") + "", data.getString("username"), data.getString("user"), data.getInt("active"))); | |
| } else { | |
| search.OnNotFound(); | |
| Toast.makeText(this, message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } | |
| } catch (JSONException e) { | |
| search.OnNotFound(); | |
| throw new RuntimeException(e); | |
| } | |
| }, error -> { | |
| search.OnNotFound(); | |
| progressDialog.dismiss(); | |
| Toast.makeText(this, getString(R.string.severError), Toast.LENGTH_LONG).show(); | |
| }) { | |
| @Override | |
| protected Map<String, String> getParams() { | |
| Map<String, String> params = new HashMap<>(); | |
| params.put("private_key", Globals.getUser(ProductActivity.this)); | |
| params.put("username_for_search", username); | |
| return params; | |
| } | |
| }; | |
| stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
| requestQueue.add(stringRequest); | |
| } | |
| private void checkPinAndSetOrder(BottomSheetDialog dialog, EditText pin_edt, int pid, String order_mobile, String order_serial,String order_link, String order_usrdsc) { | |
| AddOrder(pin_edt.getText().toString().trim(), pid, order_mobile, order_serial,order_link, order_usrdsc); | |
| dialog.dismiss(); | |
| } | |
| private boolean IsValidInputs(String mobile, String serial, String link) { | |
| if (pneedmob == 1) { | |
| if (mobile.length() < 8) { | |
| Toast.makeText(this, getString(R.string.incorrect_mobile), Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } | |
| if (pneedserial == 1) { | |
| if (serial.length() < 3) { | |
| Toast.makeText(this, getString(R.string.incorrect_serial), Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } | |
| if (pneedlink == 1) { | |
| if (link.length() < 3) { | |
| Toast.makeText(this, R.string.incorrect_link, Toast.LENGTH_SHORT).show(); | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| private void AddOrder(String pin, int mpid, String mobile, String serial, String link, String mdsc) { | |
| progressDialog.show(); | |
| RequestQueue requestQueue = Volley.newRequestQueue(this); | |
| String req_url = Globals.global_link + "user_addorder.php"; | |
| StringRequest stringRequest = new StringRequest(Request.Method.POST, req_url, response -> { | |
| progressDialog.dismiss(); | |
| try { | |
| JSONObject jresponse = new JSONObject(response); | |
| boolean status = jresponse.getBoolean("status"); | |
| String message = jresponse.getString("message"); | |
| android.util.Log.e("asan", message); | |
| if (status) { | |
| Globals.setShouldFinish(this, true); | |
| Globals.setIsNeedRefreshHomeResponse(this, true); | |
| finish(); | |
| Globals.setNeedRfrsh(this, true); | |
| Toast.makeText(this, message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } else { | |
| Toast.makeText(this, message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } | |
| } catch (JSONException e) { | |
| throw new RuntimeException(e); | |
| } | |
| }, error -> { | |
| progressDialog.dismiss(); | |
| Toast.makeText(this, getString(R.string.severError), Toast.LENGTH_LONG).show(); | |
| }) { | |
| @Override | |
| protected Map<String, String> getParams() { | |
| Map<String, String> params = new HashMap<>(); | |
| params.put("private_key", Globals.getUser(ProductActivity.this)); | |
| params.put("pin", pin); | |
| if (isOther) { | |
| params.put("other", otherUserId); | |
| } else { | |
| params.put("other", "0"); | |
| } | |
| params.put("product", String.valueOf(mpid)); | |
| if (!mobile.isEmpty()) { | |
| params.put("mobile", mobile); | |
| } | |
| if (!serial.isEmpty()) { | |
| params.put("serial", serial); | |
| } | |
| if (!link.isEmpty()) { | |
| params.put("link", link); | |
| } | |
| if (!mdsc.isEmpty()) { | |
| params.put("usrdsc", mdsc); | |
| } | |
| return params; | |
| } | |
| }; | |
| stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
| requestQueue.add(stringRequest); | |
| } | |
| private void ShowAdbalanceBottomSheet() { | |
| View view_sheet = getLayoutInflater().inflate(R.layout.bottom_sheet_addbalance, null); | |
| BottomSheetDialog dialog = new BottomSheetDialog(this); | |
| view_sheet.findViewById(R.id.cancel_btn).setOnClickListener(view1 -> dialog.dismiss()); | |
| view_sheet.findViewById(R.id.contact_telegram).setOnClickListener(view2 -> { | |
| Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tg://resolve?domain=asan_payment")); | |
| myIntent.setPackage("org.telegram.messenger"); | |
| startActivity(myIntent); | |
| dialog.dismiss(); | |
| }); | |
| view_sheet.findViewById(R.id.contact_whatsapp1).setOnClickListener(view3 -> { | |
| Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send?phone=+93790553020")); | |
| myIntent.setPackage("com.whatsapp"); | |
| startActivity(myIntent); | |
| dialog.dismiss(); | |
| }); | |
| view_sheet.findViewById(R.id.contact_whatsapp2).setOnClickListener(view4 -> { | |
| Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send?phone=+93799508452")); | |
| myIntent.setPackage("com.whatsapp"); | |
| startActivity(myIntent); | |
| dialog.dismiss(); | |
| }); | |
| view_sheet.findViewById(R.id.contact_call).setOnClickListener(view5 -> { | |
| Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "+93790553020")); | |
| startActivity(intent); | |
| dialog.dismiss(); | |
| }); | |
| dialog.setContentView(view_sheet); | |
| dialog.show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment