|
|
@ -20,6 +20,7 @@ import android.app.PendingIntent; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
|
|
|
|
import android.graphics.Typeface; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.net.Uri; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.SystemClock; |
|
|
|
import android.os.SystemClock; |
|
|
@ -28,10 +29,18 @@ import android.support.design.widget.FloatingActionButton; |
|
|
|
import android.support.design.widget.TabLayout; |
|
|
|
import android.support.design.widget.TabLayout; |
|
|
|
import android.support.v4.view.ViewPager; |
|
|
|
import android.support.v4.view.ViewPager; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
|
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
|
|
|
|
import android.text.Html; |
|
|
|
|
|
|
|
import android.text.SpannableStringBuilder; |
|
|
|
|
|
|
|
import android.text.Spanned; |
|
|
|
|
|
|
|
import android.text.TextUtils; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ImageView; |
|
|
|
|
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
import com.arlib.floatingsearchview.FloatingSearchView; |
|
|
|
import com.arlib.floatingsearchview.FloatingSearchView; |
|
|
|
|
|
|
|
import com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter; |
|
|
|
|
|
|
|
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion; |
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
import com.keylesspalace.tusky.entity.Account; |
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial; |
|
|
|
import com.mikepenz.google_material_typeface_library.GoogleMaterial; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeader; |
|
|
|
import com.mikepenz.materialdrawer.AccountHeader; |
|
|
@ -43,14 +52,17 @@ 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; |
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; |
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; |
|
|
|
|
|
|
|
import com.mikepenz.materialdrawer.model.interfaces.IProfile; |
|
|
|
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; |
|
|
|
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; |
|
|
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader; |
|
|
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader; |
|
|
|
import com.squareup.picasso.Picasso; |
|
|
|
import com.squareup.picasso.Picasso; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Stack; |
|
|
|
import java.util.Stack; |
|
|
|
|
|
|
|
|
|
|
|
import retrofit2.Call; |
|
|
|
import retrofit2.Call; |
|
|
|
import retrofit2.Callback; |
|
|
|
import retrofit2.Callback; |
|
|
|
|
|
|
|
import retrofit2.Response; |
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity { |
|
|
|
public class MainActivity extends BaseActivity { |
|
|
|
private static final String TAG = "MainActivity"; // logging tag and Volley request tag
|
|
|
|
private static final String TAG = "MainActivity"; // logging tag and Volley request tag
|
|
|
@ -59,7 +71,8 @@ public class MainActivity extends BaseActivity { |
|
|
|
private PendingIntent serviceAlarmIntent; |
|
|
|
private PendingIntent serviceAlarmIntent; |
|
|
|
private boolean notificationServiceEnabled; |
|
|
|
private boolean notificationServiceEnabled; |
|
|
|
private String loggedInAccountId; |
|
|
|
private String loggedInAccountId; |
|
|
|
Stack<Integer> pageHistory = new Stack<>(); |
|
|
|
private String loggedInAccountUsername; |
|
|
|
|
|
|
|
Stack<Integer> pageHistory = new Stack<Integer>(); |
|
|
|
private ViewPager viewPager; |
|
|
|
private ViewPager viewPager; |
|
|
|
private AccountHeader headerResult; |
|
|
|
private AccountHeader headerResult; |
|
|
|
private Drawer drawer; |
|
|
|
private Drawer drawer; |
|
|
@ -126,13 +139,9 @@ public class MainActivity extends BaseActivity { |
|
|
|
long drawerItemIdentifier = drawerItem.getIdentifier(); |
|
|
|
long drawerItemIdentifier = drawerItem.getIdentifier(); |
|
|
|
|
|
|
|
|
|
|
|
if (drawerItemIdentifier == 0) { |
|
|
|
if (drawerItemIdentifier == 0) { |
|
|
|
if (loggedInAccountId != null) { |
|
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class); |
|
|
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class); |
|
|
|
intent.putExtra("id", loggedInAccountId); |
|
|
|
intent.putExtra("id", loggedInAccountId); |
|
|
|
startActivity(intent); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
|
|
|
|
Log.e(TAG, "Logged-in account id was not obtained yet when profile was opened."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (drawerItemIdentifier == 1) { |
|
|
|
} else if (drawerItemIdentifier == 1) { |
|
|
|
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); |
|
|
|
Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); |
|
|
|
startActivity(intent); |
|
|
|
startActivity(intent); |
|
|
@ -165,6 +174,70 @@ public class MainActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
|
|
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); |
|
|
|
searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSearchTextChanged(String oldQuery, String newQuery) { |
|
|
|
|
|
|
|
if (!oldQuery.equals("") && newQuery.equals("")) { |
|
|
|
|
|
|
|
searchView.clearSuggestions(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newQuery.length() < 3) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView.showProgress(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onResponse(Call<List<Account>> call, Response<List<Account>> response) { |
|
|
|
|
|
|
|
searchView.swapSuggestions(response.body()); |
|
|
|
|
|
|
|
searchView.hideProgress(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onFailure(Call<List<Account>> call, Throwable t) { |
|
|
|
|
|
|
|
searchView.hideProgress(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSuggestionClicked(SearchSuggestion searchSuggestion) { |
|
|
|
|
|
|
|
Account accountSuggestion = (Account) searchSuggestion; |
|
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, AccountActivity.class); |
|
|
|
|
|
|
|
intent.putExtra("id", accountSuggestion.id); |
|
|
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSearchAction(String currentQuery) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { |
|
|
|
|
|
|
|
Account accountSuggestion = ((Account) item); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Picasso.with(MainActivity.this) |
|
|
|
|
|
|
|
.load(accountSuggestion.avatar) |
|
|
|
|
|
|
|
.placeholder(R.drawable.avatar_default) |
|
|
|
|
|
|
|
.into(leftIcon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; |
|
|
|
|
|
|
|
final SpannableStringBuilder str = new SpannableStringBuilder(searchStr); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str.setSpan(new android.text.style.StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
|
|
|
|
|
|
|
textView.setText(str); |
|
|
|
|
|
|
|
textView.setMaxLines(1); |
|
|
|
|
|
|
|
textView.setEllipsize(TextUtils.TruncateAt.END); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Setup the tabs and timeline pager.
|
|
|
|
// Setup the tabs and timeline pager.
|
|
|
|
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); |
|
|
|
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); |
|
|
|
String[] pageTitles = { |
|
|
|
String[] pageTitles = { |
|
|
@ -234,6 +307,13 @@ public class MainActivity extends BaseActivity { |
|
|
|
SharedPreferences preferences = getSharedPreferences( |
|
|
|
SharedPreferences preferences = getSharedPreferences( |
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); |
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); |
|
|
|
final String domain = preferences.getString("domain", null); |
|
|
|
final String domain = preferences.getString("domain", null); |
|
|
|
|
|
|
|
String id = preferences.getString("loggedInAccountId", null); |
|
|
|
|
|
|
|
String username = preferences.getString("loggedInAccountUsername", null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id != null && username != null) { |
|
|
|
|
|
|
|
loggedInAccountId = id; |
|
|
|
|
|
|
|
loggedInAccountUsername = username; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() { |
|
|
|
mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -250,12 +330,12 @@ public class MainActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
|
|
|
headerResult.addProfiles( |
|
|
|
headerResult.addProfiles( |
|
|
|
new ProfileDrawerItem() |
|
|
|
new ProfileDrawerItem() |
|
|
|
.withName(me.displayName) |
|
|
|
.withName(me.getDisplayName()) |
|
|
|
.withEmail(String.format("%s@%s", me.username, domain)) |
|
|
|
.withEmail(String.format("%s@%s", me.username, domain)) |
|
|
|
.withIcon(me.avatar) |
|
|
|
.withIcon(me.avatar) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
loggedInAccountId = me.id; |
|
|
|
onFetchUserInfoSuccess(me.id, me.username); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -265,6 +345,17 @@ public class MainActivity extends BaseActivity { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onFetchUserInfoSuccess(String id, String username) { |
|
|
|
|
|
|
|
loggedInAccountId = id; |
|
|
|
|
|
|
|
loggedInAccountUsername = username; |
|
|
|
|
|
|
|
SharedPreferences preferences = getSharedPreferences( |
|
|
|
|
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); |
|
|
|
|
|
|
|
SharedPreferences.Editor editor = preferences.edit(); |
|
|
|
|
|
|
|
editor.putString("loggedInAccountId", loggedInAccountId); |
|
|
|
|
|
|
|
editor.putString("loggedInAccountUsername", loggedInAccountUsername); |
|
|
|
|
|
|
|
editor.apply(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onFetchUserInfoFailure(Exception exception) { |
|
|
|
private void onFetchUserInfoFailure(Exception exception) { |
|
|
|
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage()); |
|
|
|
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|