parent
fe9478b46b
commit
14f3b51add
|
@ -34,8 +34,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter<MultiLinkViewHolder>{
|
||||||
|
|
||||||
private List<Bitmap> bitmaps;
|
private List<Bitmap> bitmaps;
|
||||||
private List<Integer> selecteds;
|
private List<Integer> selecteds;
|
||||||
|
private SelectionChangeListener selectionListener;
|
||||||
|
|
||||||
public MultiLinkAdapter(int length) {
|
public MultiLinkAdapter(int length, SelectionChangeListener listener) {
|
||||||
|
selectionListener = listener;
|
||||||
bitmaps = new ArrayList<>();
|
bitmaps = new ArrayList<>();
|
||||||
selecteds = new ArrayList<>();
|
selecteds = new ArrayList<>();
|
||||||
for(int i = 0; i < length; i++) {
|
for(int i = 0; i < length; i++) {
|
||||||
|
@ -71,6 +73,7 @@ public class MultiLinkAdapter extends RecyclerView.Adapter<MultiLinkViewHolder>{
|
||||||
} else {
|
} else {
|
||||||
selecteds.remove(holder.index);
|
selecteds.remove(holder.index);
|
||||||
}
|
}
|
||||||
|
selectionListener.onSelectionChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -99,6 +102,10 @@ public class MultiLinkAdapter extends RecyclerView.Adapter<MultiLinkViewHolder>{
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return bitmaps.size();
|
return bitmaps.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface SelectionChangeListener {
|
||||||
|
void onSelectionChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultiLinkViewHolder extends RecyclerView.ViewHolder {
|
class MultiLinkViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -64,8 +65,17 @@ public class MultiLinkActivity extends AppCompatActivity {
|
||||||
|
|
||||||
final Long[] ids = Arrays.copyOf(extra,extra.length,Long[].class);
|
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
|
//setup Adapter
|
||||||
adapter = new MultiLinkAdapter(ids.length);
|
adapter = new MultiLinkAdapter(ids.length,selectionListener);
|
||||||
RecyclerView listView = (RecyclerView) findViewById(R.id.link_list);
|
RecyclerView listView = (RecyclerView) findViewById(R.id.link_list);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
|
|
||||||
|
@ -120,6 +130,7 @@ public class MultiLinkActivity extends AppCompatActivity {
|
||||||
shareButton.setEnabled(true);
|
shareButton.setEnabled(true);
|
||||||
copyClipboardButton.setEnabled(true);
|
copyClipboardButton.setEnabled(true);
|
||||||
deleteImageButton.setEnabled(true);
|
deleteImageButton.setEnabled(true);
|
||||||
|
selectionListener.onSelectionChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -129,17 +140,14 @@ public class MultiLinkActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//manage the sharing button
|
//manage the sharing button
|
||||||
shareButton.setOnClickListener(new View.OnClickListener() {
|
shareButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent sendIntent = new Intent();
|
Intent sendIntent = new Intent();
|
||||||
sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
|
sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
|
||||||
List<Integer> selected = adapter.getSelecteds();
|
String output = generateShardedLink();
|
||||||
String output = baseUrl;
|
|
||||||
for(Integer index : selected) {
|
|
||||||
output += sharedHashs.get(index)+",";
|
|
||||||
}
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
|
sendIntent.putExtra(Intent.EXTRA_TEXT, output);
|
||||||
sendIntent.setType("text/plain");
|
sendIntent.setType("text/plain");
|
||||||
startActivity(sendIntent);
|
startActivity(sendIntent);
|
||||||
|
@ -151,11 +159,7 @@ public class MultiLinkActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
List<Integer> selected = adapter.getSelecteds();
|
String output = generateShardedLink();
|
||||||
String output = baseUrl;
|
|
||||||
for(Integer index : selected) {
|
|
||||||
output += sharedHashs.get(index)+",";
|
|
||||||
}
|
|
||||||
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied URL", output);
|
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied URL", output);
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
Toast.makeText(MultiLinkActivity.this,getString(R.string.copy_to_clipboard),Toast.LENGTH_SHORT).show();
|
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.support.v7.widget.RecyclerView
|
||||||
android:layout_alignParentTop="true"
|
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:id="@+id/link_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||||
app:spanCount="2"/>
|
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
|
<LinearLayout
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
|
|
Loading…
Reference in New Issue