Fix some errors
This commit is contained in:
parent
2411c553ed
commit
82384b48a5
|
@ -514,68 +514,69 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
|
|||
while (it.hasNext()) {
|
||||
Map.Entry pair = (Map.Entry)it.next();
|
||||
String label = (String)pair.getKey();
|
||||
String value = (String)pair.getValue();
|
||||
boolean verified = fieldsVerified.get(label);
|
||||
if( label != null && fieldsVerified.containsKey(label)) {
|
||||
boolean verified = fieldsVerified.get(label);
|
||||
|
||||
LinearLayout field;
|
||||
TextView labelView;
|
||||
TextView valueView;
|
||||
LinearLayout verifiedView;
|
||||
switch(i){
|
||||
case 1:
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
verifiedView = findViewById(R.id.value1BG);
|
||||
break;
|
||||
case 2:
|
||||
field = findViewById(R.id.field2);
|
||||
labelView = findViewById(R.id.label2);
|
||||
valueView = findViewById(R.id.value2);
|
||||
verifiedView = findViewById(R.id.value2BG);
|
||||
break;
|
||||
case 3:
|
||||
field = findViewById(R.id.field3);
|
||||
labelView = findViewById(R.id.label3);
|
||||
valueView = findViewById(R.id.value3);
|
||||
verifiedView = findViewById(R.id.value3BG);
|
||||
break;
|
||||
case 4:
|
||||
field = findViewById(R.id.field4);
|
||||
labelView = findViewById(R.id.label4);
|
||||
valueView = findViewById(R.id.value4);
|
||||
verifiedView = findViewById(R.id.value4BG);
|
||||
break;
|
||||
default:
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
verifiedView = findViewById(R.id.value1BG);
|
||||
break;
|
||||
}
|
||||
if( field != null && labelView != null && valueView != null) {
|
||||
switch (theme){
|
||||
case Helper.THEME_LIGHT:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_4));
|
||||
LinearLayout field;
|
||||
TextView labelView;
|
||||
TextView valueView;
|
||||
LinearLayout verifiedView;
|
||||
switch (i) {
|
||||
case 1:
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
verifiedView = findViewById(R.id.value1BG);
|
||||
break;
|
||||
case Helper.THEME_DARK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
case 2:
|
||||
field = findViewById(R.id.field2);
|
||||
labelView = findViewById(R.id.label2);
|
||||
valueView = findViewById(R.id.value2);
|
||||
verifiedView = findViewById(R.id.value2BG);
|
||||
break;
|
||||
case Helper.THEME_BLACK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_4));
|
||||
case 3:
|
||||
field = findViewById(R.id.field3);
|
||||
labelView = findViewById(R.id.label3);
|
||||
valueView = findViewById(R.id.value3);
|
||||
verifiedView = findViewById(R.id.value3BG);
|
||||
break;
|
||||
case 4:
|
||||
field = findViewById(R.id.field4);
|
||||
labelView = findViewById(R.id.label4);
|
||||
valueView = findViewById(R.id.value4);
|
||||
verifiedView = findViewById(R.id.value4BG);
|
||||
break;
|
||||
default:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
}
|
||||
field.setVisibility(View.VISIBLE);
|
||||
if( verified) {
|
||||
verifiedView.setBackgroundResource(R.drawable.verified);
|
||||
field = findViewById(R.id.field1);
|
||||
labelView = findViewById(R.id.label1);
|
||||
valueView = findViewById(R.id.value1);
|
||||
verifiedView = findViewById(R.id.value1BG);
|
||||
break;
|
||||
}
|
||||
if (field != null && labelView != null && valueView != null) {
|
||||
switch (theme) {
|
||||
case Helper.THEME_LIGHT:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_light_4));
|
||||
break;
|
||||
case Helper.THEME_DARK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
break;
|
||||
case Helper.THEME_BLACK:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_black_4));
|
||||
break;
|
||||
default:
|
||||
labelView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_2));
|
||||
valueView.setBackgroundColor(ContextCompat.getColor(ShowAccountActivity.this, R.color.notif_dark_4));
|
||||
}
|
||||
field.setVisibility(View.VISIBLE);
|
||||
if (verified) {
|
||||
verifiedView.setBackgroundResource(R.drawable.verified);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -249,6 +249,12 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
case HASHTAG:
|
||||
break;
|
||||
}
|
||||
List<String> bookmarks = new StatusCacheDAO(contextReference.get(), db).getAllStatusId(StatusCacheDAO.BOOKMARK_CACHE);
|
||||
if( apiResponse != null && apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0){
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = apiResponse.getStatuses();
|
||||
for(fr.gouv.etalab.mastodon.client.Entities.Status status: statuses)
|
||||
status.setBookmarked(bookmarks.contains(status.getId()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,11 @@ public class Status implements Parcelable{
|
|||
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||
mentions = in.readArrayList(Mention.class.getClassLoader());
|
||||
account = in.readParcelable(Account.class.getClassLoader());
|
||||
application = in.readParcelable(Application.class.getClassLoader());
|
||||
try {
|
||||
application = in.readParcelable(Application.class.getClassLoader());
|
||||
}catch (Exception e){
|
||||
application = new Application();
|
||||
}
|
||||
tags = in.readArrayList(Tag.class.getClassLoader());
|
||||
contentTranslated = in.readString();
|
||||
reblogs_count = in.readInt();
|
||||
|
|
|
@ -626,12 +626,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
//Display a preview for accounts that have replied *if enabled and only for home timeline*
|
||||
|
||||
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Status statusBookmarked = new StatusCacheDAO(context, db).getStatus(StatusCacheDAO.BOOKMARK_CACHE, status.getId());
|
||||
if( statusBookmarked != null)
|
||||
status.setBookmarked(true);
|
||||
else
|
||||
status.setBookmarked(false);
|
||||
|
||||
if( status.isNew())
|
||||
holder.new_element.setVisibility(View.VISIBLE);
|
||||
|
@ -979,6 +973,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
|
||||
status.setBookmarked(!status.isBookmarked());
|
||||
try {
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
if (status.isBookmarked()) {
|
||||
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
|
||||
Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show();
|
||||
|
@ -997,6 +992,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
if (statustmp.getId().equals(status.getId())) {
|
||||
statuses.remove(status);
|
||||
statusListAdapter.notifyItemRemoved(position);
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
|
||||
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
|
@ -1017,6 +1013,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
//-------- END -> Manages translations
|
||||
|
||||
if( status.getAccount() == null) {
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
status.setAccount(account);
|
||||
}
|
||||
|
@ -1857,6 +1854,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
case R.id.action_bookmark:
|
||||
if( type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
|
||||
status.setBookmarked(!status.isBookmarked());
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
try {
|
||||
if (status.isBookmarked()) {
|
||||
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
|
||||
|
@ -1876,6 +1874,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
if (statustmp.getId().equals(status.getId())) {
|
||||
statuses.remove(status);
|
||||
statusListAdapter.notifyItemRemoved(position);
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
|
||||
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
|
||||
break;
|
||||
|
@ -2115,6 +2114,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
toot.setSpoiler_text(status.getSpoiler_text().trim());
|
||||
toot.setVisibility(status.getVisibility());
|
||||
toot.setContent(status.getContent());
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
long id = new StatusStoredDAO(context, db).insertStatus(toot, null);
|
||||
Intent intentToot = new Intent(context, TootActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
|
|
@ -804,7 +804,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
if( this.statuses != null) {
|
||||
if( type != RetrieveFeedsAsyncTask.Type.HOME){
|
||||
if( tagTimeline == null || !tagTimeline.isART() || (tagTimeline.isART() && tagTimeline.isNSFW())) {
|
||||
if (Long.parseLong(statuses.get(i).getId()) > Long.parseLong(this.statuses.get(0).getId())) {
|
||||
if (this.statuses.size() == 0 || Long.parseLong(statuses.get(i).getId()) > Long.parseLong(this.statuses.get(0).getId())) {
|
||||
inserted++;
|
||||
this.statuses.add(0, statuses.get(i));
|
||||
}
|
||||
|
|
|
@ -224,6 +224,24 @@ public class StatusCacheDAO {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all cached Statuses in db depending of their cache type
|
||||
* @return stored status List<StoredStatus>
|
||||
*/
|
||||
public List<String> getAllStatusId(int cacheType){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, new String[]{Sqlite.COL_STATUS_ID}, Sqlite.COL_CACHED_ACTION + " = '" + cacheType+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_CREATED_AT + " DESC", null);
|
||||
return cursorToListStatusesId(c);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all cached Statuses in db depending of their cache type
|
||||
* @return stored status List<StoredStatus>
|
||||
|
@ -512,4 +530,26 @@ public class StatusCacheDAO {
|
|||
//Statuses list is returned
|
||||
return statuses;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Method to get cached statuses ID from database
|
||||
* @param c Cursor
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<String> cursorToListStatusesId(Cursor c){
|
||||
//No element found
|
||||
if (c.getCount() == 0)
|
||||
return null;
|
||||
List<String> statusesId = new ArrayList<>();
|
||||
while (c.moveToNext() ) {
|
||||
//Restore cached status
|
||||
|
||||
statusesId.add(c.getString(c.getColumnIndex(Sqlite.COL_STATUS_ID)));
|
||||
}
|
||||
//Close the cursor
|
||||
c.close();
|
||||
//Statuses list is returned
|
||||
return statusesId;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue