Avoids crashes

This commit is contained in:
tom79 2019-08-05 18:10:49 +02:00
parent 9d5129a9dd
commit 0e09591ce6
3 changed files with 95 additions and 86 deletions

View File

@ -1251,7 +1251,9 @@ public abstract class BaseMainActivity extends BaseActivity
// Retrieves instance
new RetrieveInstanceAsyncTask(getApplicationContext(), BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// Retrieves filters
new ManageFiltersAsyncTask(getApplicationContext(), GET_ALL_FILTER, null, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
new ManageFiltersAsyncTask(getApplicationContext(), GET_ALL_FILTER, null, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
/* Clean cache for statuses */

View File

@ -245,60 +245,63 @@ public class SyncTimelinesAsyncTask extends AsyncTask<Void, Void, Void> {
}
}
APIResponse apiResponse = null;
List<app.fedilab.android.client.Entities.List> lists = null;
try {
apiResponse = new API(contextReference.get()).getLists();
lists = apiResponse.getLists();
}catch (Exception ignored){ }
if( lists != null && lists.size() > 0){
//Loop through results
for(app.fedilab.android.client.Entities.List list: lists){
boolean isInDb = false;
ManageTimelines timelines_tmp = null;
for(ManageTimelines manageTimeline: manageTimelines){
if( manageTimeline.getListTimeline() == null )
continue;
if(manageTimeline.getListTimeline().getId().equals(list.getId())){
isInDb = true;
timelines_tmp = manageTimeline;
break;
}
}
if( !isInDb){
ManageTimelines manageTL = new ManageTimelines();
manageTL.setListTimeline(list);
manageTL.setDisplayed(true);
manageTL.setType(ManageTimelines.Type.LIST);
manageTL.setPosition(manageTimelines.size());
new TimelinesDAO(contextReference.get(), db).insert(manageTL);
}else{
//Update list
timelines_tmp.setListTimeline(list);
new TimelinesDAO(contextReference.get(), db).update(timelines_tmp);
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
List<app.fedilab.android.client.Entities.List> lists = null;
try {
apiResponse = new API(contextReference.get()).getLists();
lists = apiResponse.getLists();
} catch (Exception ignored) {
}
for(ManageTimelines manageTimelines: manageTimelines){
if( manageTimelines.getListTimeline() == null )
continue;
boolean shouldBeRemoved = true;
for(app.fedilab.android.client.Entities.List list: lists){
if( list.getId().equals(manageTimelines.getListTimeline().getId())){
shouldBeRemoved = false;
if (lists != null && lists.size() > 0) {
//Loop through results
for (app.fedilab.android.client.Entities.List list : lists) {
boolean isInDb = false;
ManageTimelines timelines_tmp = null;
for (ManageTimelines manageTimeline : manageTimelines) {
if (manageTimeline.getListTimeline() == null)
continue;
if (manageTimeline.getListTimeline().getId().equals(list.getId())) {
isInDb = true;
timelines_tmp = manageTimeline;
break;
}
}
if (!isInDb) {
ManageTimelines manageTL = new ManageTimelines();
manageTL.setListTimeline(list);
manageTL.setDisplayed(true);
manageTL.setType(ManageTimelines.Type.LIST);
manageTL.setPosition(manageTimelines.size());
new TimelinesDAO(contextReference.get(), db).insert(manageTL);
} else {
//Update list
timelines_tmp.setListTimeline(list);
new TimelinesDAO(contextReference.get(), db).update(timelines_tmp);
}
}
if( shouldBeRemoved){
for (ManageTimelines manageTimelines : manageTimelines) {
if (manageTimelines.getListTimeline() == null)
continue;
boolean shouldBeRemoved = true;
for (app.fedilab.android.client.Entities.List list : lists) {
if (list.getId().equals(manageTimelines.getListTimeline().getId())) {
shouldBeRemoved = false;
}
}
if (shouldBeRemoved) {
new TimelinesDAO(contextReference.get(), db).remove(manageTimelines);
}
}
} else {
for (ManageTimelines manageTimelines : manageTimelines) {
if (manageTimelines.getListTimeline() == null)
continue;
new TimelinesDAO(contextReference.get(), db).remove(manageTimelines);
}
}
}else{
for(ManageTimelines manageTimelines: manageTimelines){
if( manageTimelines.getListTimeline() == null )
continue;
new TimelinesDAO(contextReference.get(), db).remove(manageTimelines);
}
}
}
for (Iterator<ManageTimelines> it = manageTimelines.iterator(); it.hasNext();) {
if (!it.next().isDisplayed()) {
it.remove();

View File

@ -3151,25 +3151,27 @@ public class Helper {
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}catch (Exception e){
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.gnu_default_avatar)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}
try {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.gnu_default_avatar)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}
}catch (Exception ignored){}
}
}else{
try {
@ -3179,25 +3181,27 @@ public class Helper {
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}catch (Exception e){
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.gnu_default_avatar)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}
try {
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || BaseMainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.missing_peertube)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
Glide.with(imageView.getContext())
.asDrawable()
.load(R.drawable.gnu_default_avatar)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
.into(imageView);
}
}catch (Exception ignored){}
}
}