Added folder levels

pull/146/head
M66B 6 years ago
parent c1a52e91bb
commit 7483b45905

File diff suppressed because it is too large Load Diff

@ -36,7 +36,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
@ -60,6 +59,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private LifecycleOwner owner;
private long account;
private boolean debug;
private int dp12;
private List<TupleFolderEx> all = new ArrayList<>();
private List<TupleFolderEx> filtered = new ArrayList<>();
@ -67,6 +67,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
private View itemView;
private View vwColor;
private View vwLevel;
private ImageView ivState;
private TextView tvName;
private TextView tvMessages;
@ -88,6 +89,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
this.itemView = itemView.findViewById(R.id.clItem);
vwColor = itemView.findViewById(R.id.vwColor);
vwLevel = itemView.findViewById(R.id.vwLevel);
ivState = itemView.findViewById(R.id.ivState);
tvName = itemView.findViewById(R.id.tvName);
tvMessages = itemView.findViewById(R.id.tvMessages);
@ -115,6 +117,12 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
vwColor.setBackgroundColor(folder.accountColor == null ? Color.TRANSPARENT : folder.accountColor);
vwColor.setVisibility(account < 0 ? View.VISIBLE : View.GONE);
if (account > 0) {
ViewGroup.LayoutParams lp = vwLevel.getLayoutParams();
lp.width = folder.level * dp12;
vwLevel.setLayoutParams(lp);
}
if ("connected".equals(folder.state))
ivState.setImageResource(R.drawable.baseline_cloud_24);
else if ("connecting".equals(folder.state))
@ -358,6 +366,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.debug = prefs.getBoolean("debug", false);
this.dp12 = Math.round(12 * context.getResources().getDisplayMetrics().density);
setHasStableIds(true);
}

@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 13,
version = 14,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -227,6 +227,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("CREATE INDEX `index_message_ui_flagged` ON `message` (`ui_flagged`)");
}
})
.addMigrations(new Migration(13, 14) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `level` INTEGER NOT NULL DEFAULT 0");
}
})
.build();
}

@ -124,6 +124,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET type = :type WHERE id = :id")
int setFolderType(long id, String type);
@Query("UPDATE folder SET level = :level WHERE id = :id")
int setFolderLevel(long id, int level);
@Query("UPDATE folder" +
" SET type = '" + EntityFolder.USER + "'" +
" WHERE account = :account")

@ -65,6 +65,8 @@ public class EntityFolder implements Serializable {
@NonNull
public String type;
@NonNull
public Integer level;
@NonNull
public Boolean synchronize;
@NonNull
public Integer sync_days;
@ -154,6 +156,7 @@ public class EntityFolder implements Serializable {
(this.account == null ? other.account == null : this.account.equals(other.account)) &&
this.name.equals(other.name) &&
this.type.equals(other.type) &&
this.level.equals(other.level) &&
this.synchronize.equals(other.synchronize) &&
(this.display == null ? other.display == null : this.display.equals(other.display)) &&
this.hide == other.hide &&
@ -173,6 +176,7 @@ public class EntityFolder implements Serializable {
JSONObject json = new JSONObject();
json.put("name", name);
json.put("type", type);
json.put("level", level);
json.put("synchronize", synchronize);
json.put("sync_days", sync_days);
json.put("keep_days", keep_days);
@ -186,6 +190,10 @@ public class EntityFolder implements Serializable {
EntityFolder folder = new EntityFolder();
folder.name = json.getString("name");
folder.type = json.getString("type");
if (json.has("level"))
folder.level = json.getInt("level");
folder.synchronize = json.getBoolean("synchronize");
if (json.has("after"))

@ -1795,8 +1795,10 @@ public class ServiceSynchronize extends LifecycleService {
names.add(folder.name);
Log.i(Helper.TAG, "Local folder count=" + names.size());
Folder[] ifolders = istore.getDefaultFolder().list("*");
Log.i(Helper.TAG, "Remote folder count=" + ifolders.length);
Folder defaultFolder = istore.getDefaultFolder();
char separator = defaultFolder.getSeparator();
Folder[] ifolders = defaultFolder.list("*");
Log.i(Helper.TAG, "Remote folder count=" + ifolders.length + " separator=" + separator);
for (Folder ifolder : ifolders) {
boolean selectable = true;
@ -1807,20 +1809,29 @@ public class ServiceSynchronize extends LifecycleService {
}
if (selectable) {
EntityFolder folder = db.folder().getFolderByName(account.id, ifolder.getFullName());
String fullName = ifolder.getFullName();
int level = 0;
for (int i = 0; i < fullName.length(); i++)
if (fullName.charAt(i) == separator)
level++;
EntityFolder folder = db.folder().getFolderByName(account.id, fullName);
if (folder == null) {
folder = new EntityFolder();
folder.account = account.id;
folder.name = ifolder.getFullName();
folder.type = EntityFolder.USER;
folder.level = level;
folder.synchronize = false;
folder.sync_days = EntityFolder.DEFAULT_USER_SYNC;
folder.keep_days = EntityFolder.DEFAULT_USER_SYNC;
db.folder().insertFolder(folder);
Log.i(Helper.TAG, folder.name + " added");
Log.i(Helper.TAG, folder.name + " added level=" + level);
} else {
names.remove(folder.name);
Log.i(Helper.TAG, folder.name + " exists");
Log.i(Helper.TAG, folder.name + " exists level=" + level);
db.folder().setFolderLevel(folder.id, level);
}
}
}

@ -28,6 +28,30 @@
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/ivUnified"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_folder_special_24"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@+id/barrier1" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="ivState" />
<View
android:id="@+id/vwLevel"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/tvKeywords"
app:layout_constraintStart_toEndOf="@id/barrier0"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvName"
android:layout_width="0dp"
@ -40,7 +64,7 @@
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/tvAfter"
app:layout_constraintStart_toEndOf="@id/ivState"
app:layout_constraintStart_toEndOf="@id/vwLevel"
app:layout_constraintTop_toTopOf="parent" />
<TextView
@ -70,15 +94,6 @@
app:barrierDirection="bottom"
app:constraint_referenced_ids="ivState,tvName,tvMessages,ivMessages" />
<ImageView
android:id="@+id/ivUnified"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_folder_special_24"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/barrier1" />
<TextView
android:id="@+id/tvType"
android:layout_width="wrap_content"
@ -87,7 +102,7 @@
android:gravity="center_vertical"
android:text="type"
android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintStart_toEndOf="@id/ivUnified"
app:layout_constraintStart_toEndOf="@id/vwLevel"
app:layout_constraintTop_toBottomOf="@id/barrier1" />
<TextView
@ -127,7 +142,7 @@
android:text="Keywords"
android:textAppearance="@android:style/TextAppearance.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivUnified"
app:layout_constraintStart_toEndOf="@id/vwLevel"
app:layout_constraintTop_toBottomOf="@id/barrier2" />
<TextView

Loading…
Cancel
Save