(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
commit f79445f50a
5 changed files with 91 additions and 49 deletions

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