|
|
@ -44,10 +44,12 @@ import com.android.volley.Response; |
|
|
|
import com.android.volley.VolleyError; |
|
|
|
import com.android.volley.VolleyError; |
|
|
|
import com.android.volley.toolbox.JsonObjectRequest; |
|
|
|
import com.android.volley.toolbox.JsonObjectRequest; |
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
|
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeader; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeader; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeaderBuilder; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeaderBuilder; |
|
|
|
import com.mikepenz.materialdrawer.Drawer; |
|
|
|
import com.mikepenz.materialdrawer.Drawer; |
|
|
|
import com.mikepenz.materialdrawer.DrawerBuilder; |
|
|
|
import com.mikepenz.materialdrawer.DrawerBuilder; |
|
|
|
|
|
|
|
import com.mikepenz.materialdrawer.model.DividerDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; |
|
|
@ -103,22 +105,8 @@ public class MainActivity extends BaseActivity { |
|
|
|
headerResult = new AccountHeaderBuilder() |
|
|
|
headerResult = new AccountHeaderBuilder() |
|
|
|
.withActivity(this) |
|
|
|
.withActivity(this) |
|
|
|
.withSelectionListEnabledForSingleProfile(false) |
|
|
|
.withSelectionListEnabledForSingleProfile(false) |
|
|
|
.withTranslucentStatusBar(true) |
|
|
|
.withDividerBelowHeader(false) |
|
|
|
.withCompactStyle(true) |
|
|
|
.withCompactStyle(true) |
|
|
|
.withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onProfileImageClick(View view, IProfile profile, boolean current) { |
|
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class); |
|
|
|
|
|
|
|
intent.putExtra("id", loggedInAccountId); |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
DrawerImageLoader.init(new AbstractDrawerImageLoader() { |
|
|
|
DrawerImageLoader.init(new AbstractDrawerImageLoader() { |
|
|
@ -136,15 +124,16 @@ public class MainActivity extends BaseActivity { |
|
|
|
drawer = new DrawerBuilder() |
|
|
|
drawer = new DrawerBuilder() |
|
|
|
.withActivity(this) |
|
|
|
.withActivity(this) |
|
|
|
.withToolbar(toolbar) |
|
|
|
.withToolbar(toolbar) |
|
|
|
.withTranslucentStatusBar(true) |
|
|
|
|
|
|
|
.withAccountHeader(headerResult) |
|
|
|
.withAccountHeader(headerResult) |
|
|
|
.withHasStableIds(true) |
|
|
|
.withHasStableIds(true) |
|
|
|
.withSelectedItem(-1) |
|
|
|
.withSelectedItem(-1) |
|
|
|
.addDrawerItems( |
|
|
|
.addDrawerItems( |
|
|
|
new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false), |
|
|
|
new PrimaryDrawerItem().withIdentifier(0).withName(R.string.action_view_profile).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), |
|
|
|
new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_blocks)).withSelectable(false), |
|
|
|
new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), |
|
|
|
new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_preferences)).withSelectable(false), |
|
|
|
new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), |
|
|
|
new PrimaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_logout)).withSelectable(false) |
|
|
|
new DividerDrawerItem(), |
|
|
|
|
|
|
|
new SecondaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_preferences)).withSelectable(false), |
|
|
|
|
|
|
|
new SecondaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_logout)).withSelectable(false) |
|
|
|
) |
|
|
|
) |
|
|
|
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { |
|
|
|
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -152,7 +141,11 @@ public class MainActivity extends BaseActivity { |
|
|
|
if (drawerItem != null) { |
|
|
|
if (drawerItem != null) { |
|
|
|
long drawerItemIdentifier = drawerItem.getIdentifier(); |
|
|
|
long drawerItemIdentifier = drawerItem.getIdentifier(); |
|
|
|
|
|
|
|
|
|
|
|
if (drawerItemIdentifier == 1) { |
|
|
|
if (drawerItemIdentifier == 0) { |
|
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class); |
|
|
|
|
|
|
|
intent.putExtra("id", loggedInAccountId); |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
} else if (drawerItemIdentifier == 1) { |
|
|
|
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); |
|
|
|
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); |
|
|
|
startActivity(intent); |
|
|
|
startActivity(intent); |
|
|
|
} else if (drawerItemIdentifier == 2) { |
|
|
|
} else if (drawerItemIdentifier == 2) { |
|
|
@ -253,39 +246,40 @@ public class MainActivity extends BaseActivity { |
|
|
|
final String domain = preferences.getString("domain", null); |
|
|
|
final String domain = preferences.getString("domain", null); |
|
|
|
String id = preferences.getString("loggedInAccountId", null); |
|
|
|
String id = preferences.getString("loggedInAccountId", null); |
|
|
|
String username = preferences.getString("loggedInAccountUsername", null); |
|
|
|
String username = preferences.getString("loggedInAccountUsername", null); |
|
|
|
//if (id != null && username != null) {
|
|
|
|
|
|
|
|
// loggedInAccountId = id;
|
|
|
|
|
|
|
|
// loggedInAccountUsername = username;
|
|
|
|
|
|
|
|
//} else {
|
|
|
|
|
|
|
|
mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onResponse(Call<Account> call, retrofit2.Response<Account> response) { |
|
|
|
|
|
|
|
Account me = response.body(); |
|
|
|
|
|
|
|
ImageView background = headerResult.getHeaderBackgroundView(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Picasso.with(MainActivity.this) |
|
|
|
|
|
|
|
.load(me.header) |
|
|
|
|
|
|
|
.placeholder(R.drawable.account_header_missing) |
|
|
|
|
|
|
|
.resize(background.getWidth(), background.getHeight()) |
|
|
|
|
|
|
|
.centerCrop() |
|
|
|
|
|
|
|
.into(background); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
headerResult.addProfiles( |
|
|
|
|
|
|
|
new ProfileDrawerItem() |
|
|
|
|
|
|
|
.withName(me.displayName) |
|
|
|
|
|
|
|
.withEmail(String.format("%s@%s", me.username, domain)) |
|
|
|
|
|
|
|
.withIcon(me.avatar) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//onFetchUserInfoSuccess(response.body().id, response.body().username);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
if (id != null && username != null) { |
|
|
|
public void onFailure(Call<Account> call, Throwable t) { |
|
|
|
loggedInAccountId = id; |
|
|
|
onFetchUserInfoFailure((Exception) t); |
|
|
|
loggedInAccountUsername = username; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//}
|
|
|
|
mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onResponse(Call<Account> call, retrofit2.Response<Account> response) { |
|
|
|
|
|
|
|
Account me = response.body(); |
|
|
|
|
|
|
|
ImageView background = headerResult.getHeaderBackgroundView(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Picasso.with(MainActivity.this) |
|
|
|
|
|
|
|
.load(me.header) |
|
|
|
|
|
|
|
.placeholder(R.drawable.account_header_missing) |
|
|
|
|
|
|
|
.resize(background.getWidth(), background.getHeight()) |
|
|
|
|
|
|
|
.centerCrop() |
|
|
|
|
|
|
|
.into(background); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
headerResult.addProfiles( |
|
|
|
|
|
|
|
new ProfileDrawerItem() |
|
|
|
|
|
|
|
.withName(me.displayName) |
|
|
|
|
|
|
|
.withEmail(String.format("%s@%s", me.username, domain)) |
|
|
|
|
|
|
|
.withIcon(me.avatar) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//onFetchUserInfoSuccess(response.body().id, response.body().username);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onFailure(Call<Account> call, Throwable t) { |
|
|
|
|
|
|
|
onFetchUserInfoFailure((Exception) t); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onFetchUserInfoSuccess(String id, String username) { |
|
|
|
private void onFetchUserInfoSuccess(String id, String username) { |
|
|
|