(medias) try to add medias
This commit is contained in:
parent
7a7bca565e
commit
87c1edb3d4
|
@ -77,6 +77,8 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.keylesspalace.tusky.db.TootDao;
|
||||
import com.keylesspalace.tusky.db.TootEntity;
|
||||
import com.keylesspalace.tusky.entity.Account;
|
||||
|
@ -296,6 +298,22 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
startingContentWarning = intent.getStringExtra("content_warning");
|
||||
}
|
||||
}
|
||||
|
||||
/* If come from SavedTootActivity
|
||||
* */
|
||||
String savedTootText = intent.getStringExtra("saved_toot_text");
|
||||
if (!TextUtils.isEmpty(savedTootText)) {
|
||||
textEditor.append(savedTootText);
|
||||
}
|
||||
|
||||
String savedJsonUrls = intent.getStringExtra("saved_json_urls");
|
||||
if (!TextUtils.isEmpty(savedJsonUrls)) {
|
||||
// try to redo a list of media
|
||||
ArrayList<String> playersList = new Gson().fromJson(savedJsonUrls,
|
||||
new TypeToken<ArrayList<String>>() {
|
||||
}.getType());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* If the currently logged in account is locked, its posts should default to private. This
|
||||
|
@ -516,6 +534,17 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
|||
} else {
|
||||
final TootEntity toot = new TootEntity();
|
||||
toot.setText(s);
|
||||
if (mediaQueued != null && mediaQueued.size() > 0) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (QueuedMedia q :
|
||||
mediaQueued) {
|
||||
Log.d("list", "" + q.uri);
|
||||
list.add(q.uri.toString());
|
||||
}
|
||||
String json = new Gson().toJson(list);
|
||||
toot.setUrls(json);
|
||||
}
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
|
|
@ -15,14 +15,19 @@
|
|||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.keylesspalace.tusky.adapter.SavedTootAdapter;
|
||||
import com.keylesspalace.tusky.db.TootDao;
|
||||
|
@ -31,13 +36,14 @@ import com.keylesspalace.tusky.util.ThemeUtils;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class SavedTootActivity extends BaseActivity {
|
||||
public class SavedTootActivity extends BaseActivity implements SavedTootAdapter.SavedTootAction {
|
||||
|
||||
// dao
|
||||
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
|
||||
|
||||
// ui
|
||||
private SavedTootAdapter adapter;
|
||||
private TextView noContent;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -46,8 +52,15 @@ public class SavedTootActivity extends BaseActivity {
|
|||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ActionBar bar = getSupportActionBar();
|
||||
if (bar != null) {
|
||||
bar.setTitle(getString(R.string.title_saved_toot));
|
||||
bar.setDisplayHomeAsUpEnabled(true);
|
||||
bar.setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
noContent = (TextView) findViewById(R.id.no_content);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
@ -57,12 +70,24 @@ public class SavedTootActivity extends BaseActivity {
|
|||
R.drawable.status_divider_dark);
|
||||
divider.setDrawable(drawable);
|
||||
recyclerView.addItemDecoration(divider);
|
||||
adapter = new SavedTootAdapter();
|
||||
adapter = new SavedTootAdapter(this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
// req
|
||||
getAllToot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void getAllToot() {
|
||||
new AsyncTask<Void, Void, List<TootEntity>>() {
|
||||
@Override
|
||||
|
@ -76,9 +101,38 @@ public class SavedTootActivity extends BaseActivity {
|
|||
for (TootEntity t : tootEntities) {
|
||||
Log.e("toot", "id=" + t.getUid() + "text=" + t.getText());
|
||||
}
|
||||
|
||||
// set ui
|
||||
setNoContent(tootEntities.size());
|
||||
adapter.addItems(tootEntities);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void setNoContent(int size) {
|
||||
if (size == 0) {
|
||||
noContent.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
noContent.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(int position, TootEntity item) {
|
||||
// update DB
|
||||
tootDao.delete(item);
|
||||
// update adapter
|
||||
if (adapter != null) {
|
||||
adapter.removeItem(position);
|
||||
setNoContent(adapter.getItemCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(int position, TootEntity item) {
|
||||
Intent intent = new Intent(this, ComposeActivity.class);
|
||||
intent.putExtra("saved_toot_text", item.getText());
|
||||
intent.putExtra("saved_json_urls", item.getUrls());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
package com.keylesspalace.tusky.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
|
@ -32,10 +33,12 @@ import java.util.List;
|
|||
|
||||
public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||
private List<TootEntity> list;
|
||||
private SavedTootAction handler;
|
||||
|
||||
public SavedTootAdapter() {
|
||||
public SavedTootAdapter(Context context) {
|
||||
super();
|
||||
list = new ArrayList<>();
|
||||
handler = (SavedTootAction) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,33 +51,12 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
|||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
TootViewHolder holder = (TootViewHolder) viewHolder;
|
||||
holder.bind(getItem(position));
|
||||
holder.bind(position, getItem(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size() + 1;
|
||||
}
|
||||
|
||||
public void update(List<TootEntity> newToot) {
|
||||
if (newToot == null || newToot.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
list = newToot;
|
||||
} else {
|
||||
int index = list.indexOf(newToot.get(newToot.size() - 1));
|
||||
for (int i = 0; i < index; i++) {
|
||||
list.remove(0);
|
||||
}
|
||||
int newIndex = newToot.indexOf(list.get(0));
|
||||
if (newIndex == -1) {
|
||||
list.addAll(0, newToot);
|
||||
} else {
|
||||
list.addAll(0, newToot.subList(0, newIndex));
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public void addItems(List<TootEntity> newToot) {
|
||||
|
@ -93,14 +75,6 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
|||
return toot;
|
||||
}
|
||||
|
||||
public void addItem(TootEntity toot, int position) {
|
||||
if (position < 0 || position > list.size()) {
|
||||
return;
|
||||
}
|
||||
list.add(position, toot);
|
||||
notifyItemInserted(position);
|
||||
}
|
||||
|
||||
public TootEntity getItem(int position) {
|
||||
if (position >= 0 && position < list.size()) {
|
||||
return list.get(position);
|
||||
|
@ -108,6 +82,13 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
|||
return null;
|
||||
}
|
||||
|
||||
// handler saved toot
|
||||
public interface SavedTootAction {
|
||||
void delete(int position, TootEntity item);
|
||||
|
||||
void click(int position, TootEntity item);
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView mTextView;
|
||||
|
||||
|
@ -117,21 +98,37 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
|||
}
|
||||
}
|
||||
|
||||
private static class TootViewHolder extends RecyclerView.ViewHolder {
|
||||
public TextView content;
|
||||
public ImageButton suppr;
|
||||
private class TootViewHolder extends RecyclerView.ViewHolder {
|
||||
View view;
|
||||
TextView content;
|
||||
ImageButton suppr;
|
||||
|
||||
TootViewHolder(View view) {
|
||||
super(view);
|
||||
content = (TextView) view.findViewById(R.id.content);
|
||||
suppr = (ImageButton) view.findViewById(R.id.suppr);
|
||||
this.view = view;
|
||||
this.content = (TextView) view.findViewById(R.id.content);
|
||||
this.suppr = (ImageButton) view.findViewById(R.id.suppr);
|
||||
}
|
||||
|
||||
public void bind(TootEntity item) {
|
||||
if (item != null && !TextUtils.isEmpty(item.getText()))
|
||||
void bind(final int position, final TootEntity item) {
|
||||
if (item != null) {
|
||||
if (!TextUtils.isEmpty(item.getText()))
|
||||
content.setText(item.getText());
|
||||
else
|
||||
content.setText("");
|
||||
suppr.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handler.delete(position, item);
|
||||
}
|
||||
});
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
handler.click(position, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import android.arch.persistence.room.RoomDatabase;
|
|||
* DB version & declare DAO
|
||||
*/
|
||||
|
||||
@Database(entities = {TootEntity.class}, version = 2, exportSchema = false)
|
||||
abstract public class AppDatabase extends RoomDatabase {
|
||||
@Database(entities = {TootEntity.class}, version = 3, exportSchema = false)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract TootDao tootDao();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ public class TootEntity {
|
|||
@ColumnInfo(name = "text")
|
||||
private String text;
|
||||
|
||||
@ColumnInfo(name = "urls")
|
||||
private String urls;
|
||||
|
||||
// getter setter
|
||||
public String getText() {
|
||||
return text;
|
||||
|
@ -32,4 +35,12 @@ public class TootEntity {
|
|||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
public void setUrls(String urls) {
|
||||
this.urls = urls;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:padding="16dp"
|
||||
android:layout_margin="16dp"
|
||||
|
||||
android:contentDescription="@string/action_unmute"
|
||||
app:srcCompat="@drawable/ic_clear_24dp" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue