Created
December 23, 2025 13:22
-
-
Save sajjadyousefnia/8f1fa9fea24bfde16e7eaaff50e0ac34 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; | |
| import android.content.ActivityNotFoundException; | |
| import android.content.ClipData; | |
| import android.content.ClipboardManager; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.pm.PackageManager; | |
| import android.content.res.ColorStateList; | |
| import android.graphics.Bitmap; | |
| import android.graphics.Canvas; | |
| import android.graphics.Color; | |
| import android.graphics.drawable.Drawable; | |
| import android.net.Uri; | |
| import android.os.Build; | |
| import android.os.Bundle; | |
| import android.os.Environment; | |
| import android.provider.MediaStore; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.FrameLayout; | |
| import android.widget.ImageView; | |
| import android.widget.TextView; | |
| import android.widget.Toast; | |
| import androidx.annotation.NonNull; | |
| import androidx.core.content.FileProvider; | |
| import androidx.fragment.app.Fragment; | |
| import androidx.recyclerview.widget.LinearLayoutManager; | |
| import androidx.recyclerview.widget.RecyclerView; | |
| 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.auth.LoginActivity; | |
| import com.asantech.asanpay.databinding.FragmentHome2Binding; | |
| import com.asantech.asanpay.setting.Globals; | |
| import com.asantech.asanpay.user.MessagesActivity; | |
| import com.denzcoskun.imageslider.constants.ScaleTypes; | |
| import com.denzcoskun.imageslider.models.SlideModel; | |
| import com.google.android.material.bottomsheet.BottomSheetBehavior; | |
| import com.google.android.material.bottomsheet.BottomSheetDialog; | |
| import com.squareup.picasso.Picasso; | |
| import com.squareup.picasso.Target; | |
| import org.json.JSONArray; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.File; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.text.DecimalFormat; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.Map; | |
| public class HomeFragment extends Fragment { | |
| private FragmentHome2Binding binding; | |
| private RequestQueue requestQueue; | |
| private StringRequest stringRequest; | |
| String priceHolder; | |
| public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
| binding = FragmentHome2Binding.inflate(inflater, container, false); | |
| View root = binding.getRoot(); | |
| binding.addBalanceIv.setOnClickListener(v -> ShowAdbalanceBottomSheet()); | |
| binding.addBalanceTv.setOnClickListener(v -> ShowAdbalanceBottomSheet()); | |
| binding.addBalanceArrow.setOnClickListener(v -> ShowAdbalanceBottomSheet()); | |
| binding.moreTransactions.setOnClickListener(v -> { | |
| ((FirstActivity) requireActivity()).binding.navView.setSelectedItemId(R.id.navigation_orders); | |
| }); | |
| binding.notifIbtn.setOnClickListener(v -> { | |
| startActivity(new Intent(requireActivity(), MessagesActivity.class)); | |
| }); | |
| binding.supportIbtn.setOnClickListener(v -> { | |
| ShowSupportBottomSheet(); | |
| }); | |
| ApplyResponse(); | |
| GetHome(); | |
| binding.getRoot().setOnRefreshListener(this::GetHome); | |
| binding.recyclerView.setLayoutManager(new LinearLayoutManager(requireActivity(), RecyclerView.HORIZONTAL, false)); | |
| ApplyResponserRcyclr(); | |
| ArrayList<SlideModel> imageList = new ArrayList<>(); | |
| imageList.add(new SlideModel(R.drawable.bnr1, ScaleTypes.FIT)); | |
| imageList.add(new SlideModel(R.drawable.bnr2, ScaleTypes.FIT)); | |
| imageList.add(new SlideModel(R.drawable.bnr3, ScaleTypes.FIT)); | |
| binding.imageSlider.setImageList(imageList); | |
| binding.imageSlider.startSliding(2000); | |
| return root; | |
| } | |
| private void ShowAdbalanceBottomSheet() { | |
| View view_sheet = getLayoutInflater().inflate(R.layout.bottom_sheet_addbalance, null); | |
| BottomSheetDialog dialog = new BottomSheetDialog(requireActivity()); | |
| 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(); | |
| } | |
| private void ShowSupportBottomSheet() { | |
| View view_sheet = getLayoutInflater().inflate(R.layout.bottom_sheet_support, null); | |
| BottomSheetDialog dialog = new BottomSheetDialog(requireActivity()); | |
| 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 -> { | |
| openWhatsApp(view3.getContext(), "+93790553020"); | |
| dialog.dismiss(); | |
| }); | |
| view_sheet.findViewById(R.id.contact_whatsapp2).setOnClickListener(view4 -> { | |
| openWhatsApp(view4.getContext(), "+93799508452"); | |
| 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(); | |
| } | |
| @Override | |
| public void onDestroyView() { | |
| super.onDestroyView(); | |
| if (requestQueue != null) { | |
| requestQueue.cancelAll("ALL"); | |
| } | |
| if (stringRequest != null) { | |
| stringRequest.cancel(); | |
| } | |
| } | |
| private void GetHome() { | |
| requestQueue = Volley.newRequestQueue(requireActivity()); | |
| String req_url = Globals.global_link + "user_home_new.php"; | |
| stringRequest = new StringRequest(Request.Method.POST, req_url, response -> { | |
| binding.getRoot().setRefreshing(false); | |
| try { | |
| JSONObject jresponse = new JSONObject(response); | |
| boolean status = jresponse.getBoolean("status"); | |
| String message = jresponse.getString("message"); | |
| if (status) { | |
| Globals.setResponseHome(requireActivity(), response); | |
| ApplyResponse(); | |
| ApplyResponserRcyclr(); | |
| } else { | |
| Toast.makeText(requireActivity(), message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } | |
| } catch (JSONException ignored) { | |
| } | |
| }, error -> { | |
| binding.getRoot().setRefreshing(false); | |
| Toast.makeText(requireActivity(), 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(requireActivity())); | |
| params.put("lang", Globals.getLanguage(requireActivity())); | |
| return params; | |
| } | |
| }; | |
| stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
| stringRequest.setTag("ALL"); | |
| requestQueue.add(stringRequest); | |
| } | |
| private void getWidget() { | |
| requestQueue = Volley.newRequestQueue(requireActivity()); | |
| String req_url = Globals.global_link + "user_widget.php"; | |
| stringRequest = new StringRequest(Request.Method.POST, req_url, response -> { | |
| try { | |
| JSONObject jresponse = new JSONObject(response); | |
| boolean status = jresponse.getBoolean("status"); | |
| String message = jresponse.getString("message"); | |
| String totalOrders = jresponse.getString("totalOrders"); | |
| String totalAmount = jresponse.getString("totalAmount"); | |
| String totalProfit = jresponse.getString("totalProfit"); | |
| String totalDebt = jresponse.getString("totalDebt"); | |
| if (status) { | |
| binding.salesNumber.setText(totalOrders + ""); | |
| binding.buyMoneyCount.setText(totalAmount + ""); | |
| binding.soodTv.setText(getString(R.string.profit) + totalProfit); | |
| binding.tvBedehi.setText(getString(R.string.settleMent) + totalDebt); | |
| binding.tvCurrencySood.setText(priceHolder); | |
| binding.tvCurrencyBedehi.setText(priceHolder); | |
| binding.tvOrders.setText(getString(R.string.order_prices_all) + "(" + priceHolder + ")"); | |
| binding.tvOrderCount.setText(R.string.order_count); | |
| } else { | |
| Toast.makeText(requireActivity(), message.split(":")[1], Toast.LENGTH_LONG).show(); | |
| } | |
| } catch (JSONException ignored) { | |
| } | |
| }, error -> { | |
| Toast.makeText(requireActivity(), 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(requireActivity())); | |
| params.put("lang", Globals.getLanguage(requireActivity())); | |
| return params; | |
| } | |
| }; | |
| stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); | |
| stringRequest.setTag("ALL"); | |
| requestQueue.add(stringRequest); | |
| } | |
| public void ApplyResponse() { | |
| if (Globals.getResponseHome(requireActivity()) != null) { | |
| try { | |
| JSONObject jresponse = new JSONObject(Globals.getResponseHome(requireActivity())); | |
| boolean status = jresponse.getBoolean("status"); | |
| String name = jresponse.getString("name"); | |
| Boolean isLeader = jresponse.getBoolean("is_leader"); | |
| int leaderCount = jresponse.getInt("subordinates_count"); | |
| String currency = jresponse.getString("currency"); | |
| App.Companion.setShowPrice(jresponse.getInt("show_price") == 1); | |
| String balance = jresponse.getString("balance"); | |
| int disremains = jresponse.getInt("disremains"); | |
| int unread = jresponse.getInt("unread"); | |
| if (status) { | |
| if (jresponse.getInt("active") == 0) { | |
| Globals.setUser(requireActivity(), null); | |
| requireActivity().startActivity(new Intent(requireActivity(), LoginActivity.class)); | |
| requireActivity().finish(); | |
| } | |
| binding.nameTv.setText(name); | |
| /* switch (currency) { | |
| case "usd": { | |
| binding.balanceTv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.usd_crncy))); | |
| } | |
| break; | |
| case "afg": { | |
| binding.balanceTv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.afg_crncy))); | |
| } | |
| break; | |
| case "irt": { | |
| binding.balanceTv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), getString(R.string.irt_crncy))); | |
| } | |
| break; | |
| }*/ | |
| 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; | |
| } | |
| } | |
| binding.balanceTv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(Double.valueOf(balance)), priceHolder)); | |
| //order count | |
| //salesNumber | |
| //sales money | |
| //buyMoneyCount | |
| //soodTv | |
| //tvBedehi | |
| getWidget(); | |
| if (disremains > 0) { | |
| binding.discuntView.setVisibility(View.VISIBLE); | |
| if (disremains > 24 * 60 * 60) { | |
| binding.xMoretimeTv.setText((disremains / (24 * 60 * 60)) + " " + getString(R.string.x_more_days)); | |
| } else if (disremains > 60 * 60) { | |
| binding.xMoretimeTv.setText((disremains / (60 * 60)) + " " + getString(R.string.x_more_hours)); | |
| } else { | |
| binding.xMoretimeTv.setText(Math.max(disremains / 60, 1) + " " + getString(R.string.x_more_minitues)); | |
| } | |
| } else { | |
| binding.discuntView.setVisibility(View.GONE); | |
| } | |
| if (unread == 1) { | |
| binding.badgeIv.setVisibility(View.VISIBLE); | |
| } else { | |
| binding.badgeIv.setVisibility(View.GONE); | |
| } | |
| } | |
| } catch (JSONException ignored) { | |
| ignored.printStackTrace(); | |
| } | |
| } | |
| } | |
| private void ApplyResponserRcyclr() { | |
| if (Globals.getResponseHome(requireActivity()) != null) { | |
| try { | |
| JSONObject jresponse = new JSONObject(Globals.getResponseHome(requireActivity())); | |
| String ucurrency = jresponse.getString("currency"); | |
| String name = jresponse.getString("name"); | |
| String mobile = jresponse.getString("mobile"); | |
| JSONArray orders_id = jresponse.getJSONArray("orders_id"); | |
| JSONArray orders_pid = jresponse.getJSONArray("orders_pid"); | |
| JSONArray orders_pcid = jresponse.getJSONArray("orders_pcid"); | |
| JSONArray orders_price = jresponse.getJSONArray("orders_price"); | |
| JSONArray orders_price_show = jresponse.getJSONArray("orders_price_show"); | |
| JSONArray orders_status = jresponse.getJSONArray("orders_status"); | |
| JSONArray orders_udsc = jresponse.getJSONArray("orders_udsc"); | |
| JSONArray orders_dsc = jresponse.getJSONArray("orders_dsc"); | |
| JSONArray orders_date = jresponse.getJSONArray("orders_date"); | |
| JSONArray orders_pname = jresponse.getJSONArray("orders_pname"); | |
| JSONArray orders_pimage = jresponse.getJSONArray("orders_pimage"); | |
| JSONArray orders_needmob = jresponse.getJSONArray("orders_needmob"); | |
| JSONArray orders_needser = jresponse.getJSONArray("orders_needser"); | |
| JSONArray orders_needlink = jresponse.getJSONArray("orders_needlink"); | |
| JSONArray cats2_id = jresponse.getJSONArray("cats2_id"); | |
| JSONArray cats2_name = jresponse.getJSONArray("cats2_name"); | |
| JSONArray orders_ptitle = new JSONArray(); | |
| for (int i = 0; i < orders_pcid.length(); i++) { | |
| boolean isset = false; | |
| for (int j = 0; j < cats2_id.length(); j++) { | |
| if (orders_pcid.getInt(i) == cats2_id.getInt(j)) { | |
| orders_ptitle.put(cats2_name.getString(j)); | |
| isset = true; | |
| break; | |
| } | |
| } | |
| if (!isset) { | |
| orders_ptitle.put(""); | |
| } | |
| } | |
| if (orders_id.length() == 0) { | |
| binding.empty.setVisibility(View.VISIBLE); | |
| } else { | |
| binding.empty.setVisibility(View.INVISIBLE); | |
| } | |
| binding.recyclerView.setAdapter(new RcyclerAdapter(requireActivity(), ucurrency, name, mobile, orders_id, orders_pid, orders_price, orders_price_show, | |
| orders_status, orders_udsc, orders_dsc, orders_date, orders_pimage, orders_ptitle, orders_pname, orders_needmob, orders_needser, orders_needlink)); | |
| } catch (Exception ignored) { | |
| } | |
| } | |
| } | |
| private Bitmap ViewToBitmap(final View view) { | |
| Bitmap mBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); | |
| Canvas canvas = new Canvas(mBitmap); | |
| Drawable bgDrawable = view.getBackground(); | |
| if (bgDrawable != null) { | |
| bgDrawable.draw(canvas); | |
| } else { | |
| canvas.drawColor(Color.WHITE); | |
| } | |
| view.draw(canvas); | |
| return mBitmap; | |
| } | |
| private class RcyclerAdapter extends RecyclerView.Adapter<RcyclerAdapter.mViewHolder> { | |
| Context context; | |
| String crnc, uname, mobile; | |
| JSONArray orders_id, orders_product, orders_price, orders_price_show, orders_status, orders_udsc, orders_dsc, orders_date, orders_img, orders_title, orders_name, orders_needmob, orders_needser, orders_needlink; | |
| private RcyclerAdapter(Context context, String crnc, String uname, String mobile, JSONArray orders_id, JSONArray orders_product, JSONArray orders_price, JSONArray orders_price_show, JSONArray orders_status, JSONArray orders_udsc, JSONArray orders_dsc, JSONArray orders_date, JSONArray orders_img, JSONArray orders_title, JSONArray orders_name, JSONArray orders_needmob, JSONArray orders_needser, JSONArray orders_needlink) { | |
| this.context = context; | |
| this.crnc = crnc; | |
| this.mobile = mobile; | |
| this.uname = uname; | |
| this.orders_id = orders_id; | |
| this.orders_product = orders_product; | |
| this.orders_price_show = orders_price_show; | |
| this.orders_price = orders_price; | |
| this.orders_status = orders_status; | |
| this.orders_udsc = orders_udsc; | |
| this.orders_dsc = orders_dsc; | |
| this.orders_date = orders_date; | |
| this.orders_title = orders_title; | |
| this.orders_name = orders_name; | |
| this.orders_img = orders_img; | |
| this.orders_needmob = orders_needmob; | |
| this.orders_needser = orders_needser; | |
| this.orders_needlink = orders_needlink; | |
| } | |
| @NonNull | |
| @Override | |
| public RcyclerAdapter.mViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | |
| View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.last_transaction_item, parent, false); | |
| return new RcyclerAdapter.mViewHolder(itemView); | |
| } | |
| @Override | |
| public void onBindViewHolder(@NonNull mViewHolder holder, int position) { | |
| try { | |
| String priceHolder = getString(R.string.usd_crncy); | |
| switch (crnc) { | |
| 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; | |
| } | |
| } | |
| /* switch (crnc) { | |
| case "usd": { | |
| holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.usd_crncy))); | |
| } | |
| break; | |
| case "afg": { | |
| holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.afg_crncy))); | |
| } | |
| break; | |
| case "irt": { | |
| holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.irt_crncy))); | |
| } | |
| break; | |
| }*/ | |
| holder.price_tv.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price_show.getDouble(position)), priceHolder)); | |
| String stts = getString(R.string.ordrs_pending); | |
| switch (orders_status.getInt(position)) { | |
| case 1: { | |
| stts = getString(R.string.ordrs_done); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| holder.status_tv.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#0ED300"))); | |
| } else { | |
| holder.status_tv.setBackgroundColor(Color.parseColor("#0ED300")); | |
| } | |
| } | |
| break; | |
| case 0: { | |
| stts = getString(R.string.ordrs_pending); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| holder.status_tv.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FBC02D"))); | |
| } else { | |
| holder.status_tv.setBackgroundColor(Color.parseColor("#FBC02D")); | |
| } | |
| } | |
| break; | |
| case -1: { | |
| stts = getString(R.string.ordrs_rejected); | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| holder.status_tv.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FF0000"))); | |
| } else { | |
| holder.status_tv.setBackgroundColor(Color.parseColor("#FF0000")); | |
| } | |
| } | |
| break; | |
| } | |
| holder.status_tv.setText(stts); | |
| holder.title_tv.setText(orders_title.getString(position)); | |
| holder.dsc_tv.setText(orders_name.getString(position)); | |
| Picasso.get().load(Globals.global_link + "images/" + orders_img.getString(position)).into(new Target() { | |
| @Override | |
| public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { | |
| holder.main_iv.setImageBitmap(bitmap); | |
| holder.main_iv.setBackgroundColor(bitmap.getPixel(10, 10)); | |
| } | |
| @Override | |
| public void onBitmapFailed(Exception e, Drawable errorDrawable) { | |
| } | |
| @Override | |
| public void onPrepareLoad(Drawable placeHolderDrawable) { | |
| } | |
| }); | |
| holder.share_iv.setOnClickListener(v -> { | |
| View view_sheet = getLayoutInflater().inflate(R.layout.bottom_sheet_share, null); | |
| BottomSheetDialog dialog = new BottomSheetDialog(requireActivity()); | |
| dialog.setOnShowListener(dialogInterface -> { | |
| BottomSheetDialog d = (BottomSheetDialog) dialogInterface; | |
| FrameLayout bottomSheet = d.findViewById(com.google.android.material.R.id.design_bottom_sheet); | |
| BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(bottomSheet); | |
| if (behavior != null) { | |
| behavior.setState(BottomSheetBehavior.STATE_EXPANDED); | |
| } | |
| }); | |
| TextView detail_dsc1 = view_sheet.findViewById(R.id.detail_dsc1); | |
| TextView detail_dsc2 = view_sheet.findViewById(R.id.detail_dsc2); | |
| TextView detail_dsc3 = view_sheet.findViewById(R.id.detail_dsc3); | |
| TextView detail_dsc4 = view_sheet.findViewById(R.id.detail_dsc4); | |
| TextView detail_dsc5 = view_sheet.findViewById(R.id.detail_dsc5); | |
| TextView detail_dsc6 = view_sheet.findViewById(R.id.detail_dsc6); | |
| TextView detail_dsc7 = view_sheet.findViewById(R.id.detail_dsc7); | |
| TextView detail_dsc8 = view_sheet.findViewById(R.id.detail_dsc8); | |
| TextView detail_dsc88 = view_sheet.findViewById(R.id.detail_dsc88); | |
| TextView detail_sub88 = view_sheet.findViewById(R.id.detail_sub88); | |
| TextView detail_dsc9 = view_sheet.findViewById(R.id.detail_dsc9); | |
| try { | |
| if (App.Companion.isShowPrice()) { | |
| detail_sub88.setVisibility(View.VISIBLE); | |
| detail_dsc88.setVisibility(View.VISIBLE); | |
| } else { | |
| detail_sub88.setVisibility(View.GONE); | |
| detail_dsc88.setVisibility(View.GONE); | |
| } | |
| String s1 = "#" + orders_id.getString(position); | |
| detail_dsc1.setText(s1); | |
| detail_dsc2.setText(orders_name.getString(position)); | |
| String mob = orders_needmob.getString(position); | |
| String ser = orders_needser.getString(position); | |
| String link = orders_needlink.getString(position); | |
| if (mob != null && !mob.equalsIgnoreCase("null") && !mob.equalsIgnoreCase("")) { | |
| detail_dsc3.setText(mob); | |
| } else if (ser != null && !ser.equalsIgnoreCase("null") && !ser.equalsIgnoreCase("")){ | |
| detail_dsc3.setText(ser); | |
| }else{ | |
| detail_dsc3.setText(link); | |
| } | |
| // | |
| // detail_dsc88.setText(mobile); | |
| /*if (mobile.equals("null")) { | |
| detail_dsc88.setText("-"); | |
| }*/ | |
| /* if (Globals.isNotNullTxt(orders_needmob.getString(position))) { | |
| detail_dsc88.setText(orders_needmob.getString(position)); | |
| }*/ | |
| detail_dsc4.setText(orders_date.getString(position)); | |
| detail_dsc7.setText(uname); | |
| String s8 = orders_dsc.getString(position); | |
| String s9 = orders_udsc.getString(position); | |
| if (s9 != null && s9.startsWith("Sent ")) { | |
| String amount = s9.split(" ")[1]; | |
| detail_dsc2.setText(orders_name.getString(position) + " (" + amount + ")"); | |
| } else { | |
| detail_dsc2.setText(orders_name.getString(position)); | |
| } | |
| detail_dsc8.setText(s8); | |
| detail_dsc8.setOnClickListener(v1 -> { | |
| ClipboardManager clipboard = (ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE); | |
| ClipData clip = ClipData.newPlainText(s1, s8); | |
| clipboard.setPrimaryClip(clip); | |
| Toast.makeText(context, getString(R.string.copied), Toast.LENGTH_SHORT).show(); | |
| }); | |
| detail_dsc9.setText(s9); | |
| detail_dsc9.setOnClickListener(v1 -> { | |
| ClipboardManager clipboard = (ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE); | |
| ClipData clip = ClipData.newPlainText(s1, s9); | |
| clipboard.setPrimaryClip(clip); | |
| Toast.makeText(context, getString(R.string.copied), Toast.LENGTH_SHORT).show(); | |
| }); | |
| switch (crnc) { | |
| case "usd": { | |
| detail_dsc6.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.usd_crncy))); | |
| detail_dsc88.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price_show.getDouble(position)), getString(R.string.usd_crncy))); | |
| } | |
| break; | |
| case "afg": { | |
| detail_dsc6.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.afg_crncy))); | |
| detail_dsc88.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price_show.getDouble(position)), getString(R.string.afg_crncy))); | |
| } | |
| break; | |
| case "irt": { | |
| detail_dsc6.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.irt_crncy))); | |
| detail_dsc88.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price_show.getDouble(position)), getString(R.string.irt_crncy))); | |
| } | |
| break; | |
| case "lir": { | |
| detail_dsc6.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price.getDouble(position)), getString(R.string.lir_crncy))); | |
| detail_dsc88.setText(String.format("%s %s", new DecimalFormat("#,###.##").format(orders_price_show.getDouble(position)), getString(R.string.lir_crncy))); | |
| } | |
| break; | |
| } | |
| switch (orders_status.getInt(position)) { | |
| case -1: { | |
| detail_dsc5.setText(getString(R.string.ordrs_rejected)); | |
| detail_dsc5.setTextColor(getResources().getColor(R.color.color_order_reject)); | |
| } | |
| break; | |
| case 0: { | |
| detail_dsc5.setText(getString(R.string.ordrs_pending)); | |
| detail_dsc5.setTextColor(getResources().getColor(R.color.color_order_pending)); | |
| } | |
| break; | |
| case 1: { | |
| detail_dsc5.setText(getString(R.string.ordrs_done)); | |
| detail_dsc5.setTextColor(getResources().getColor(R.color.color_order_accept)); | |
| } | |
| break; | |
| } | |
| } catch (JSONException ignored) { | |
| } | |
| view_sheet.findViewById(R.id.cancel_btn).setOnClickListener(view1 -> dialog.dismiss()); | |
| view_sheet.findViewById(R.id.image_btn).setOnClickListener(view1 -> { | |
| Bitmap b = ViewToBitmap(view_sheet.findViewById(R.id.share_content_layout)); | |
| if (b == null) { | |
| Toast.makeText(requireActivity(), R.string.error_image, Toast.LENGTH_SHORT).show(); | |
| dialog.dismiss(); | |
| return; | |
| } | |
| try { | |
| // ذخیره در پوشه Downloads | |
| File downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); | |
| String fileName = "asan_factor_" + System.currentTimeMillis() + ".jpg"; | |
| File file = new File(downloadsDir, fileName); | |
| FileOutputStream fos = new FileOutputStream(file); | |
| b.compress(Bitmap.CompressFormat.JPEG, 100, fos); | |
| fos.flush(); | |
| fos.close(); | |
| Toast.makeText(requireActivity(), R.string.save_done, Toast.LENGTH_SHORT).show(); | |
| dialog.dismiss(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| Toast.makeText(requireActivity(), "خطا:" + e.getMessage(), Toast.LENGTH_LONG).show(); | |
| dialog.dismiss(); | |
| } | |
| }); | |
| view_sheet.findViewById(R.id.confirm_btn).setOnClickListener(view1 -> { | |
| Bitmap b = ViewToBitmap(view_sheet.findViewById(R.id.share_content_layout)); | |
| if (b == null) { | |
| Toast.makeText(requireActivity(), "خطا در ایجاد تصویر", Toast.LENGTH_SHORT).show(); | |
| dialog.dismiss(); | |
| return; | |
| } | |
| try { | |
| // ذخیره در حافظه موقت اپ | |
| File file = new File(requireActivity().getCacheDir(), "asan_factor_" + System.currentTimeMillis() + ".jpg"); | |
| FileOutputStream outputStream = new FileOutputStream(file); | |
| b.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); | |
| outputStream.close(); | |
| // ساخت URI با FileProvider | |
| Uri fileUri = FileProvider.getUriForFile( | |
| requireActivity(), | |
| requireActivity().getPackageName() + ".fileprovider", | |
| file | |
| ); | |
| // اشتراکگذاری | |
| Intent share = new Intent(Intent.ACTION_SEND); | |
| share.setType("image/jpeg"); | |
| share.putExtra(Intent.EXTRA_STREAM, fileUri); | |
| share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |
| startActivity(Intent.createChooser(share, "Select")); | |
| dialog.dismiss(); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| Toast.makeText(requireActivity(), "خطا در اشتراک تصویر", Toast.LENGTH_SHORT).show(); | |
| dialog.dismiss(); | |
| } | |
| }); | |
| dialog.setContentView(view_sheet); | |
| dialog.show(); | |
| }); | |
| holder.copy_iv.setOnClickListener(v -> { | |
| try { | |
| String status_st = ""; | |
| switch (orders_status.getInt(position)) { | |
| case -1: { | |
| status_st = getString(R.string.ordrs_rejected); | |
| } | |
| break; | |
| case 0: { | |
| status_st = getString(R.string.ordrs_pending); | |
| } | |
| break; | |
| case 1: { | |
| status_st = getString(R.string.ordrs_done); | |
| } | |
| break; | |
| } | |
| String mob; | |
| if (Globals.isNotNullTxt(orders_needmob.getString(position))) { | |
| mob = orders_needmob.getString(position); | |
| } else { | |
| if (Globals.isNotNullTxt(mobile)) { | |
| mob = mobile; | |
| } else { | |
| mob = "-"; | |
| } | |
| } | |
| String morder_string = getString(R.string.share_order_number) + "#" + orders_id.getString(position) + "\n_____\n" + getString(R.string.share_product) + orders_name.getString(position) + "\n_____\n" + getString(R.string.user) + uname + "\n_____\n" + getString(R.string.share_mobile_number) + mob + "\n_____\n" + getString(R.string.share_order_date) + orders_date.getString(position) + "\n_____\n" + getString(R.string.share_order_status) + status_st + "\n_____\n" + getString(R.string.user_desc) + orders_udsc.getString(position) | |
| + "\n_____\n" + getString(R.string.admin_desc) + orders_dsc.getString(position) | |
| + "\nhttps://www.asan-pay.com\n"; | |
| ClipboardManager clipboard = (ClipboardManager) requireActivity().getSystemService(Context.CLIPBOARD_SERVICE); | |
| ClipData clip = ClipData.newPlainText(getString(R.string.share_order), morder_string); | |
| clipboard.setPrimaryClip(clip); | |
| Toast.makeText(context, getString(R.string.copied), Toast.LENGTH_SHORT).show(); | |
| } catch (JSONException ignored) { | |
| } | |
| }); | |
| } catch (JSONException ignored) { | |
| } | |
| } | |
| @Override | |
| public int getItemCount() { | |
| return Math.min(orders_id.length(), 10); | |
| } | |
| class mViewHolder extends RecyclerView.ViewHolder { | |
| final ImageView main_iv, share_iv, copy_iv; | |
| final TextView title_tv, dsc_tv, price_tv, status_tv; | |
| mViewHolder(@NonNull View itemView) { | |
| super(itemView); | |
| main_iv = itemView.findViewById(R.id.main_iv); | |
| share_iv = itemView.findViewById(R.id.share_iv); | |
| copy_iv = itemView.findViewById(R.id.copy_iv); | |
| title_tv = itemView.findViewById(R.id.title_tv); | |
| dsc_tv = itemView.findViewById(R.id.dsc_tv); | |
| price_tv = itemView.findViewById(R.id.price_tv); | |
| status_tv = itemView.findViewById(R.id.status_tv); | |
| } | |
| } | |
| } | |
| // Function to handle WhatsApp or WhatsApp Business | |
| private void openWhatsApp(Context context, String phoneNumber) { | |
| String url = "https://api.whatsapp.com/send?phone=" + phoneNumber; | |
| Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
| // Check if WhatsApp or WhatsApp Business is installed | |
| if (isAppInstalled(context, "com.whatsapp")) { | |
| intent.setPackage("com.whatsapp"); | |
| } else if (isAppInstalled(context, "com.whatsapp.w4b")) { // WhatsApp Business package name | |
| intent.setPackage("com.whatsapp.w4b"); | |
| } | |
| try { | |
| context.startActivity(intent); | |
| } catch (ActivityNotFoundException e) { | |
| Toast.makeText(context, "Neither WhatsApp nor WhatsApp Business is installed.", Toast.LENGTH_SHORT).show(); | |
| } | |
| } | |
| // Utility function to check if an app is installed | |
| private boolean isAppInstalled(Context context, String packageName) { | |
| try { | |
| context.getPackageManager().getPackageInfo(packageName, 0); | |
| return true; | |
| } catch (PackageManager.NameNotFoundException e) { | |
| return false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment