1

私はアンドロイドアプリを開発しています。一部のデータが から取得され、アプリFirebaseDatabaseの に表示されています。RecyclerView

RecyclerViewが入っていますcards。すべてのカードに、画像とテキストが表示されます。カードには「共有」ボタンがあり、クリックするdynamic-linkと生成され、誰とでも共有されます。共有された動的リンクをクリックすると、アプリが開き、共有ボタンがクリックされたのと同じカードにあった画像が表示されますが、テキストは常に最後に保存されたデータが表示されます。あなたが私の主張を理解したことを願っています。

これが私が生成している方法ですdynamic-link

        Button btnShare = (Button) holder.itemView.findViewById(R.id.btn_share);
        btnShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Uri BASE_URL = Uri.parse("http://www.appwebsite.com/");
                holder.APP_URI = BASE_URL.buildUpon().path(imageUIDh).build();

                packageName = holder.itemView.getContext().getPackageName();

                deepLinkTS = Uri.parse("https://u9p25.app.goo.gl/?link="+holder.APP_URI+"&apn="+packageName+"&amv="+16+"&ad="+0);

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT, "Please help this needy: " + deepLinkTS.toString() + "\n-shared through app.");

                holder.itemView.getContext().startActivity(Intent.createChooser(intent, "Share via..."));

            }
        });

の方法で処理dynamic-linkするonCreate()方法は次のMainActivity.classとおりです。

boolean autoLaunchDeepLink = false;
        AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, MainActivity.this, autoLaunchDeepLink)
                .setResultCallback(
                        new ResultCallback<AppInviteInvitationResult>() {
                            @Override
                            public void onResult(@NonNull AppInviteInvitationResult result) {
                                if (result.getStatus().isSuccess()) {
                                    // Extract deep link from Intent
                                    Intent intent = result.getInvitationIntent();
                                    final String deepLink = AppInviteReferral.getDeepLink(intent);

                                    // Handle the deep link. For example, open the linked
                                    // content, or apply promotional credit to the user's
                                    // account.

                                    final ProgressDialog openingSharedRequest = new ProgressDialog(MainActivity.this);
                                    openingSharedRequest.setMessage("Opening shared help-request...");
                                    openingSharedRequest.show();

                                    Handler handler = new Handler();
                                    handler.postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Intent helpRequestIntent = new Intent(MainActivity.this, HelpRequestThroughDeepLink.class);
                                            helpRequestIntent.putExtra("deepLink", deepLink);
//                                            helpRequestIntent.putExtra("deepLinkTS", HelpRequest.deepLinkTS.toString());
//                                    helpRequestIntent.putExtra("APP_URI", HelpRequest.ViewHolder.APP_URI.toString());
                                            helpRequestIntent.putExtra("postedFrom", postedFromS);
//                                    new AlertDialog.Builder(MainActivity.this)
//                                            .setMessage(deepLink)
//                                            .setPositiveButton("OK", null)
//                                            .create()
//                                            .show();
                                            startActivity(helpRequestIntent);
                                            openingSharedRequest.dismiss();
                                        }
                                    }, 1200);

                                    // [START_EXCLUDE]
                                    // Display deep link in the UI
//                                        ((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
                                    // [END_EXCLUDE]
                                } else {
//                                        Log.d(TAG, "getInvitation: no deep link found.");
//                                    Toast.makeText(getBaseContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
        // [END get_deep_link]

からのコードは次のHelpRequestThroughDeepLink.javaとおりです。

public class HelpRequestThroughDeepLink extends AppCompatActivity {

    String deepLink, deepLinkTS, APP_URI, imageUID, imageUIDFD, hDescription;
    Button btn_accept, btn_reject;
    ImageView hImageHDL;
    TextView imageUIDHDL, hDescriptionHDL;
    DatabaseReference databaseReference1, databaseReferenceUsers;
    MapView mapView;
    ProgressBar progressBar;
    CoordinatorLayout coordinatorLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_request_through_deep_link);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.myCoordinatorLayout);

        databaseReference1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://humanehelper-e8a22.firebaseio.com/");
        databaseReferenceUsers = FirebaseDatabase.getInstance().getReferenceFromUrl("https://humanehelper-e8a22.firebaseio.com/users");

        if (getIntent().getExtras() != null) {
            deepLink = getIntent().getExtras().getString("deepLink");
            deepLinkTS = getIntent().getExtras().getString("deepLinkTS");
            APP_URI = getIntent().getExtras().getString("APP_URI");
            postedFrom = getIntent().getExtras().getString("postedFrom");
            String imageUIDD = deepLink.substring(28);
            try {
                imageUID = URLDecoder.decode(imageUIDD, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            if (isNetworkAvailable()) {
                operateDeepLinkRequest();
            } else {
                Snackbar.make(findViewById(R.id.myCoordinatorLayout), "No internet connection!", Snackbar.LENGTH_LONG)
                        .setAction("RETRY", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                ifNetworkAvailable();
                            }
                        })
                        .setDuration(Snackbar.LENGTH_INDEFINITE)
                        .show();
            }

        } else {
            Toast.makeText(getBaseContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
        }

        hImageHDL = (ImageView) findViewById(R.id.hImageHDL);
        imageUIDHDL = (TextView) findViewById(R.id.imageUIDHDL);
        hDescriptionHDL = (TextView) findViewById(R.id.homelessDescriptionHDL);

        btn_accept = (Button) findViewById(R.id.btn_accept);
        btn_reject = (Button) findViewById(R.id.btn_reject);
        progressBar = (ProgressBar) findViewById(R.id.progressBar_loading_image);

    }

    public void operateDeepLinkRequest() {
        if (deepLink.contains(imageUID)) {
            if ((imageUID.startsWith("https://firebasestorage.googleapis.com/") || imageUID.startsWith("content://"))) {

                retrieveRespectiveRequest();

            }
        }
    }

    public void retrieveRespectiveRequest() {
        databaseReference1.child("help-requests").addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                Map<String, String> newRequest = (Map<String, String>) dataSnapshot.getValue();
                imageUIDFD = newRequest.get("imageUIDh");
                hDescription = newRequest.get("hDescription");

                progressBar.setVisibility(View.VISIBLE);

                    imageUIDHDL.setText(imageUID);
                    doSomethingWithPicaso(imageUID, hImageHDL);
                    hDescriptionHDL.setText(hDescription);

            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

        databaseReference1.child("help-requests").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

    }

    private void doSomethingWithPicaso(String imageUIDh, ImageView target){
//        Picasso.with(itemView.getContext()).cancelRequest(homelessImage);
        Picasso.with(getBaseContext())
                .load(imageUIDh)
                .error(R.drawable.ic_warning_black_24dp)
                .into(target, new Callback() {
                    @Override
                    public void onSuccess() {
                        progressBar.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onError() {
                        Toast.makeText(getBaseContext(), "Error occurred while loading images. Please retry.", Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.INVISIBLE);
                    }
                });
    }

    private boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager
                = (ConnectivityManager) HelpRequestThroughDeepLink.this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public void ifNetworkAvailable(){
        if (isNetworkAvailable()) {
            operateDeepLinkRequest();
        } else {
            Snackbar.make(findViewById(R.id.myCoordinatorLayout), "No internet connection!", Snackbar.LENGTH_LONG)
                    .setAction("RETRY", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ifNetworkAvailable();
                        }
                    })
                    .setDuration(Snackbar.LENGTH_INDEFINITE)
                    .show();
        }
    }

}

どうすればこれを達成できるか教えてください。

4

0 に答える 0