(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.TextView;
|
||||||
import android.widget.Toast;
|
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.TootDao;
|
||||||
import com.keylesspalace.tusky.db.TootEntity;
|
import com.keylesspalace.tusky.db.TootEntity;
|
||||||
import com.keylesspalace.tusky.entity.Account;
|
import com.keylesspalace.tusky.entity.Account;
|
||||||
|
@ -296,6 +298,22 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
|
||||||
startingContentWarning = intent.getStringExtra("content_warning");
|
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
|
/* 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 {
|
} else {
|
||||||
final TootEntity toot = new TootEntity();
|
final TootEntity toot = new TootEntity();
|
||||||
toot.setText(s);
|
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>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
|
@ -15,14 +15,19 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky;
|
package com.keylesspalace.tusky;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
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.adapter.SavedTootAdapter;
|
||||||
import com.keylesspalace.tusky.db.TootDao;
|
import com.keylesspalace.tusky.db.TootDao;
|
||||||
|
@ -31,13 +36,14 @@ import com.keylesspalace.tusky.util.ThemeUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SavedTootActivity extends BaseActivity {
|
public class SavedTootActivity extends BaseActivity implements SavedTootAdapter.SavedTootAction {
|
||||||
|
|
||||||
// dao
|
// dao
|
||||||
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
|
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
|
||||||
|
|
||||||
// ui
|
// ui
|
||||||
private SavedTootAdapter adapter;
|
private SavedTootAdapter adapter;
|
||||||
|
private TextView noContent;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -46,8 +52,15 @@ public class SavedTootActivity extends BaseActivity {
|
||||||
|
|
||||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(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);
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||||
|
noContent = (TextView) findViewById(R.id.no_content);
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
@ -57,12 +70,24 @@ public class SavedTootActivity extends BaseActivity {
|
||||||
R.drawable.status_divider_dark);
|
R.drawable.status_divider_dark);
|
||||||
divider.setDrawable(drawable);
|
divider.setDrawable(drawable);
|
||||||
recyclerView.addItemDecoration(divider);
|
recyclerView.addItemDecoration(divider);
|
||||||
adapter = new SavedTootAdapter();
|
adapter = new SavedTootAdapter(this);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
// req
|
||||||
getAllToot();
|
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() {
|
public void getAllToot() {
|
||||||
new AsyncTask<Void, Void, List<TootEntity>>() {
|
new AsyncTask<Void, Void, List<TootEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,9 +101,38 @@ public class SavedTootActivity extends BaseActivity {
|
||||||
for (TootEntity t : tootEntities) {
|
for (TootEntity t : tootEntities) {
|
||||||
Log.e("toot", "id=" + t.getUid() + "text=" + t.getText());
|
Log.e("toot", "id=" + t.getUid() + "text=" + t.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set ui
|
||||||
|
setNoContent(tootEntities.size());
|
||||||
adapter.addItems(tootEntities);
|
adapter.addItems(tootEntities);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.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;
|
package com.keylesspalace.tusky.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -32,10 +33,12 @@ import java.util.List;
|
||||||
|
|
||||||
public class SavedTootAdapter extends RecyclerView.Adapter {
|
public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
private List<TootEntity> list;
|
private List<TootEntity> list;
|
||||||
|
private SavedTootAction handler;
|
||||||
|
|
||||||
public SavedTootAdapter() {
|
public SavedTootAdapter(Context context) {
|
||||||
super();
|
super();
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
|
handler = (SavedTootAction) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,33 +51,12 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
TootViewHolder holder = (TootViewHolder) viewHolder;
|
TootViewHolder holder = (TootViewHolder) viewHolder;
|
||||||
holder.bind(getItem(position));
|
holder.bind(position, getItem(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return list.size() + 1;
|
return list.size();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItems(List<TootEntity> newToot) {
|
public void addItems(List<TootEntity> newToot) {
|
||||||
|
@ -93,14 +75,6 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
return toot;
|
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) {
|
public TootEntity getItem(int position) {
|
||||||
if (position >= 0 && position < list.size()) {
|
if (position >= 0 && position < list.size()) {
|
||||||
return list.get(position);
|
return list.get(position);
|
||||||
|
@ -108,6 +82,13 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
return null;
|
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 {
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView mTextView;
|
TextView mTextView;
|
||||||
|
|
||||||
|
@ -117,21 +98,37 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TootViewHolder extends RecyclerView.ViewHolder {
|
private class TootViewHolder extends RecyclerView.ViewHolder {
|
||||||
public TextView content;
|
View view;
|
||||||
public ImageButton suppr;
|
TextView content;
|
||||||
|
ImageButton suppr;
|
||||||
|
|
||||||
TootViewHolder(View view) {
|
TootViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
content = (TextView) view.findViewById(R.id.content);
|
this.view = view;
|
||||||
suppr = (ImageButton) view.findViewById(R.id.suppr);
|
this.content = (TextView) view.findViewById(R.id.content);
|
||||||
|
this.suppr = (ImageButton) view.findViewById(R.id.suppr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(TootEntity item) {
|
void bind(final int position, final TootEntity item) {
|
||||||
if (item != null && !TextUtils.isEmpty(item.getText()))
|
if (item != null) {
|
||||||
content.setText(item.getText());
|
if (!TextUtils.isEmpty(item.getText()))
|
||||||
else
|
content.setText(item.getText());
|
||||||
content.setText("");
|
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
|
* DB version & declare DAO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Database(entities = {TootEntity.class}, version = 2, exportSchema = false)
|
@Database(entities = {TootEntity.class}, version = 3, exportSchema = false)
|
||||||
abstract public class AppDatabase extends RoomDatabase {
|
public abstract class AppDatabase extends RoomDatabase {
|
||||||
|
|
||||||
public abstract TootDao tootDao();
|
public abstract TootDao tootDao();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class TootEntity {
|
||||||
@ColumnInfo(name = "text")
|
@ColumnInfo(name = "text")
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
|
@ColumnInfo(name = "urls")
|
||||||
|
private String urls;
|
||||||
|
|
||||||
// getter setter
|
// getter setter
|
||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
|
@ -32,4 +35,12 @@ public class TootEntity {
|
||||||
public void setUid(int uid) {
|
public void setUid(int uid) {
|
||||||
this.uid = 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_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
android:padding="16dp"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
|
|
||||||
android:contentDescription="@string/action_unmute"
|
android:contentDescription="@string/action_unmute"
|
||||||
app:srcCompat="@drawable/ic_clear_24dp" />
|
app:srcCompat="@drawable/ic_clear_24dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue