(clean) keep it simple , don't polluted ComposeActivity, commented and moving the code

This commit is contained in:
torrentcome 2017-06-29 12:03:44 +02:00
parent 9d21c36758
commit f79445f50a
5 changed files with 91 additions and 49 deletions

View file

@ -76,8 +76,7 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.keylesspalace.tusky.db.TootDao;
import com.keylesspalace.tusky.db.TootEntity;
import com.keylesspalace.tusky.db.TootAction;
import com.keylesspalace.tusky.entity.Account;
import com.keylesspalace.tusky.entity.Media;
import com.keylesspalace.tusky.entity.Status;
@ -155,7 +154,6 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
private int currentFlags;
private Uri photoUploadUri;
private TootDao tootDao = TuskyApplication.getDB().tootDao();
/**
@ -181,7 +179,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility);
postProgress = (ProgressBar) findViewById(R.id.postProgress);
getTheToot();
TootAction.getAllToot();
// Setup the toolbar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@ -1216,47 +1214,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
@Override
public void onBackPressed() {
saveTheToot();
TootAction.saveTheToot(textEditor.getText().toString());
super.onBackPressed();
}
private void getTheToot() {
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());
}
}
}.execute();
}
private void saveTheToot() {
final TootEntity toot = new TootEntity();
toot.setText(textEditor.getText().toString());
new AsyncTask<Void, Void, Long>() {
@Override
protected Long doInBackground(Void... params) {
long tootId = tootDao.insert(toot);
if(!mediaQueued.isEmpty()){
}
return -1L;
}
@Override
protected void onPostExecute(Long aLong) {
super.onPostExecute(aLong);
}
}.execute();
}
@Override
public void onReceiveHeaderInfo(ParserUtils.HeaderInfo headerInfo) {

View file

@ -4,7 +4,7 @@ import android.arch.persistence.room.Database;
import android.arch.persistence.room.RoomDatabase;
/**
* Created by cto3543 on 28/06/2017.
* DB version & declare DAO
*/
@Database(entities = {TootEntity.class}, version = 2, exportSchema = false)

View file

@ -2,17 +2,46 @@ package com.keylesspalace.tusky.db;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.ForeignKey;
import android.arch.persistence.room.PrimaryKey;
/**
* Created by cto3543 on 28/06/2017.
* Media model
*/
@Entity
@Entity(foreignKeys = @ForeignKey(entity = TootEntity.class,
parentColumns = "uid",
childColumns = "toot_id"))
public class MediaEntity {
@PrimaryKey
@ColumnInfo(name = "toot_id")
private int toot_id;
@PrimaryKey(autoGenerate = true)
private int uid;
@ColumnInfo(name = "url")
private String text;
private String url;
// getter setter
public int getToot_id() {
return toot_id;
}
public void setToot_id(int toot_id) {
this.toot_id = toot_id;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View file

@ -0,0 +1,51 @@
package com.keylesspalace.tusky.db;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import com.keylesspalace.tusky.TuskyApplication;
import java.util.List;
/**
* Created by cto3543 on 29/06/2017.
*
*/
public class TootAction {
private static TootDao tootDao = TuskyApplication.getDB().tootDao();
public static 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());
}
}
}.execute();
}
public static void saveTheToot(String s) {
if (!TextUtils.isEmpty(s)) {
final TootEntity toot = new TootEntity();
toot.setText(s);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
tootDao.insert(toot);
return null;
}
}.execute();
}
}
}

View file

@ -5,7 +5,7 @@ import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
/**
* Created by cto3543 on 28/06/2017.
* toot model
*/
@Entity
@ -16,7 +16,7 @@ public class TootEntity {
@ColumnInfo(name = "text")
private String text;
// set get
// getter setter
public String getText() {
return text;
}