(saved_toot) add part of saved toot activity
This commit is contained in:
parent
3928febf5b
commit
6447f407c7
@ -26,6 +26,10 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".SavedTootActivity"
|
||||||
|
android:configChanges="orientation|screenSize|keyboardHidden">
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".LoginActivity"
|
android:name=".LoginActivity"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
/* Copyright 2017 Andrew Dawson
|
||||||
|
*
|
||||||
|
* This file is a part of Tusky.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
package com.keylesspalace.tusky;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Bundle;
|
||||||
|
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 com.keylesspalace.tusky.adapter.SavedTootAdapter;
|
||||||
|
import com.keylesspalace.tusky.db.TootDao;
|
||||||
|
import com.keylesspalace.tusky.db.TootEntity;
|
||||||
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SavedTootActivity extends BaseActivity {
|
||||||
|
|
||||||
|
// dao
|
||||||
|
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
|
||||||
|
|
||||||
|
// ui
|
||||||
|
private SavedTootAdapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_saved_toot);
|
||||||
|
|
||||||
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
|
recyclerView.setLayoutManager(layoutManager);
|
||||||
|
DividerItemDecoration divider = new DividerItemDecoration(
|
||||||
|
this, layoutManager.getOrientation());
|
||||||
|
Drawable drawable = ThemeUtils.getDrawable(this, R.attr.status_divider_drawable,
|
||||||
|
R.drawable.status_divider_dark);
|
||||||
|
divider.setDrawable(drawable);
|
||||||
|
recyclerView.addItemDecoration(divider);
|
||||||
|
adapter = new SavedTootAdapter();
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
getAllToot();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getAllToot() {
|
||||||
|
new AsyncTask<Void, Void, List<TootEntity>>() {
|
||||||
|
@Override
|
||||||
|
protected List<TootEntity> doInBackground(Void... params) {
|
||||||
|
return tootDao.loadAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(List<TootEntity> tootEntities) {
|
||||||
|
super.onPostExecute(tootEntities);
|
||||||
|
for (TootEntity t : tootEntities) {
|
||||||
|
Log.e("toot", "id=" + t.getUid() + "text=" + t.getText());
|
||||||
|
}
|
||||||
|
adapter.addItems(tootEntities);
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,137 @@
|
|||||||
|
/* Copyright 2017 Andrew Dawson
|
||||||
|
*
|
||||||
|
* This file is a part of Tusky.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
package com.keylesspalace.tusky.adapter;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.keylesspalace.tusky.R;
|
||||||
|
import com.keylesspalace.tusky.db.TootEntity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SavedTootAdapter extends RecyclerView.Adapter {
|
||||||
|
private List<TootEntity> list;
|
||||||
|
|
||||||
|
public SavedTootAdapter() {
|
||||||
|
super();
|
||||||
|
list = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.item_saved_toot, parent, false);
|
||||||
|
return new TootViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||||
|
TootViewHolder holder = (TootViewHolder) viewHolder;
|
||||||
|
holder.bind(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItems(List<TootEntity> newToot) {
|
||||||
|
int end = list.size();
|
||||||
|
list.addAll(newToot);
|
||||||
|
notifyItemRangeInserted(end, newToot.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public TootEntity removeItem(int position) {
|
||||||
|
if (position < 0 || position >= list.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
TootEntity toot = list.remove(position);
|
||||||
|
notifyItemRemoved(position);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
TextView mTextView;
|
||||||
|
|
||||||
|
public ViewHolder(TextView v) {
|
||||||
|
super(v);
|
||||||
|
mTextView = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TootViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
public TextView content;
|
||||||
|
public ImageButton suppr;
|
||||||
|
|
||||||
|
TootViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
content = (TextView) view.findViewById(R.id.content);
|
||||||
|
suppr = (ImageButton) view.findViewById(R.id.suppr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bind(TootEntity item) {
|
||||||
|
if (item != null && !TextUtils.isEmpty(item.getText()))
|
||||||
|
content.setText(item.getText());
|
||||||
|
else
|
||||||
|
content.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
app/src/main/res/layout/activity_saved_toot.xml
Normal file
28
app/src/main/res/layout/activity_saved_toot.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/activity_view_thread"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="com.keylesspalace.tusky.AccountListActivity">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<android.support.v7.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:background="?attr/toolbar_background_color"
|
||||||
|
android:elevation="4dp" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</android.support.design.widget.CoordinatorLayout>
|
24
app/src/main/res/layout/item_saved_toot.xml
Normal file
24
app/src/main/res/layout/item_saved_toot.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.91"
|
||||||
|
android:padding="8dp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/suppr"
|
||||||
|
style="?attr/image_button_style"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:contentDescription="@string/action_unmute"
|
||||||
|
app:srcCompat="@drawable/ic_clear_24dp" />
|
||||||
|
</LinearLayout>
|
@ -101,6 +101,7 @@
|
|||||||
<string name="action_accept">Accept</string>
|
<string name="action_accept">Accept</string>
|
||||||
<string name="action_reject">Reject</string>
|
<string name="action_reject">Reject</string>
|
||||||
<string name="action_search">Search</string>
|
<string name="action_search">Search</string>
|
||||||
|
<string name="action_access_saved_toot">Saved Toot</string>
|
||||||
|
|
||||||
<string name="send_status_link_to">Share toot URL to…</string>
|
<string name="send_status_link_to">Share toot URL to…</string>
|
||||||
<string name="send_status_content_to">Share toot to…</string>
|
<string name="send_status_content_to">Share toot to…</string>
|
||||||
@ -194,4 +195,7 @@
|
|||||||
<string name="status_media_video">Video</string>
|
<string name="status_media_video">Video</string>
|
||||||
|
|
||||||
<string name="state_follow_requested">Follow requested</string>
|
<string name="state_follow_requested">Follow requested</string>
|
||||||
|
|
||||||
|
<string name="combine_s1_s2">%1$s %2$s</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user