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

main
torrentcome 8 years ago
parent ac3ef867c1
commit 3928febf5b
  1. 44
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  2. 2
      app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java
  3. 39
      app/src/main/java/com/keylesspalace/tusky/db/MediaEntity.java
  4. 51
      app/src/main/java/com/keylesspalace/tusky/db/TootAction.java
  5. 4
      app/src/main/java/com/keylesspalace/tusky/db/TootEntity.java

@ -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) {

@ -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)

@ -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;
}
}

@ -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();
}
}
}

@ -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;
}

Loading…
Cancel
Save