diff --git a/app/src/main/java/fr/mobdev/goblim/MultiLinkAdapter.java b/app/src/main/java/fr/mobdev/goblim/MultiLinkAdapter.java index 3e3b049..b5fc26a 100644 --- a/app/src/main/java/fr/mobdev/goblim/MultiLinkAdapter.java +++ b/app/src/main/java/fr/mobdev/goblim/MultiLinkAdapter.java @@ -34,8 +34,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter{ private List bitmaps; private List selecteds; + private SelectionChangeListener selectionListener; - public MultiLinkAdapter(int length) { + public MultiLinkAdapter(int length, SelectionChangeListener listener) { + selectionListener = listener; bitmaps = new ArrayList<>(); selecteds = new ArrayList<>(); for(int i = 0; i < length; i++) { @@ -71,6 +73,7 @@ public class MultiLinkAdapter extends RecyclerView.Adapter{ } else { selecteds.remove(holder.index); } + selectionListener.onSelectionChanged(); } }; @@ -99,6 +102,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter{ public int getItemCount() { return bitmaps.size(); } + + public interface SelectionChangeListener { + void onSelectionChanged(); + } } class MultiLinkViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/fr/mobdev/goblim/activity/MultiLinkActivity.java b/app/src/main/java/fr/mobdev/goblim/activity/MultiLinkActivity.java index b6bbf76..daa055b 100644 --- a/app/src/main/java/fr/mobdev/goblim/activity/MultiLinkActivity.java +++ b/app/src/main/java/fr/mobdev/goblim/activity/MultiLinkActivity.java @@ -29,6 +29,7 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.ImageButton; +import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; @@ -64,8 +65,17 @@ public class MultiLinkActivity extends AppCompatActivity { final Long[] ids = Arrays.copyOf(extra,extra.length,Long[].class); + final MultiLinkAdapter.SelectionChangeListener selectionListener = new MultiLinkAdapter.SelectionChangeListener() { + @Override + public void onSelectionChanged() { + String generatedSharedLink = generateShardedLink(); + TextView tv = (TextView) findViewById(R.id.link); + tv.setText(generatedSharedLink); + } + }; + //setup Adapter - adapter = new MultiLinkAdapter(ids.length); + adapter = new MultiLinkAdapter(ids.length,selectionListener); RecyclerView listView = (RecyclerView) findViewById(R.id.link_list); listView.setAdapter(adapter); @@ -120,6 +130,7 @@ public class MultiLinkActivity extends AppCompatActivity { shareButton.setEnabled(true); copyClipboardButton.setEnabled(true); deleteImageButton.setEnabled(true); + selectionListener.onSelectionChanged(); } }); @@ -129,17 +140,14 @@ public class MultiLinkActivity extends AppCompatActivity { + //manage the sharing button shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE); - List selected = adapter.getSelecteds(); - String output = baseUrl; - for(Integer index : selected) { - output += sharedHashs.get(index)+","; - } + String output = generateShardedLink(); sendIntent.putExtra(Intent.EXTRA_TEXT, output); sendIntent.setType("text/plain"); startActivity(sendIntent); @@ -151,11 +159,7 @@ public class MultiLinkActivity extends AppCompatActivity { @Override public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - List selected = adapter.getSelecteds(); - String output = baseUrl; - for(Integer index : selected) { - output += sharedHashs.get(index)+","; - } + String output = generateShardedLink(); android.content.ClipData clip = android.content.ClipData.newPlainText("Copied URL", output); clipboard.setPrimaryClip(clip); Toast.makeText(MultiLinkActivity.this,getString(R.string.copy_to_clipboard),Toast.LENGTH_SHORT).show(); @@ -221,4 +225,13 @@ public class MultiLinkActivity extends AppCompatActivity { } }); } + + private String generateShardedLink() { + List selected = adapter.getSelecteds(); + String output = baseUrl; + for(Integer index : selected) { + output += sharedHashs.get(index)+","; + } + return output; + } } diff --git a/app/src/main/res/layout/multilink.xml b/app/src/main/res/layout/multilink.xml index 2583268..779fa0a 100644 --- a/app/src/main/res/layout/multilink.xml +++ b/app/src/main/res/layout/multilink.xml @@ -34,13 +34,26 @@ + +