Commit 14f3b51a authored by Schoumi's avatar Schoumi

Add Link in multilink activity

Fixes #16
parent fe9478b4
......@@ -34,8 +34,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter<MultiLinkViewHolder>{
private List<Bitmap> bitmaps;
private List<Integer> 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<MultiLinkViewHolder>{
} else {
selecteds.remove(holder.index);
}
selectionListener.onSelectionChanged();
}
};
......@@ -99,6 +102,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter<MultiLinkViewHolder>{
public int getItemCount() {
return bitmaps.size();
}
public interface SelectionChangeListener {
void onSelectionChanged();
}
}
class MultiLinkViewHolder extends RecyclerView.ViewHolder {
......
......@@ -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<Integer> 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<Integer> 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<Integer> selected = adapter.getSelecteds();
String output = baseUrl;
for(Integer index : selected) {
output += sharedHashs.get(index)+",";
}
return output;
}
}
......@@ -34,13 +34,26 @@
<android.support.v7.widget.RecyclerView
android:layout_alignParentTop="true"
android:layout_above="@id/buttons_layout"
android:layout_centerHorizontal="true"
android:layout_above="@+id/link"
android:id="@+id/link_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:spanCount="2"/>
<TextView
android:layout_above="@+id/buttons_layout"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="@+id/link"
android:layout_marginBottom="30dp"
/>
<LinearLayout
android:layout_alignParentBottom="true"
android:gravity="center"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment