The merge conflict is resolved.

This commit is contained in:
Vavassor 2017-03-10 20:50:49 -05:00
commit db36ea79d3
14 changed files with 277 additions and 91 deletions

View File

@ -61,6 +61,7 @@ public class AccountActivity extends BaseActivity {
private boolean isSelf;
private String openInWebUrl;
private TabLayout tabLayout;
private Account loadedAccount;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -170,6 +171,8 @@ public class AccountActivity extends BaseActivity {
}
private void onObtainAccountSuccess(Account account) {
loadedAccount = account;
TextView username = (TextView) findViewById(R.id.account_username);
TextView displayName = (TextView) findViewById(R.id.account_display_name);
TextView note = (TextView) findViewById(R.id.account_note);
@ -180,7 +183,7 @@ public class AccountActivity extends BaseActivity {
getString(R.string.status_username_format), account.username);
username.setText(usernameFormatted);
displayName.setText(account.displayName);
displayName.setText(account.getDisplayName());
note.setText(account.note);
note.setLinksClickable(true);
@ -448,6 +451,12 @@ public class AccountActivity extends BaseActivity {
onBackPressed();
return true;
}
case R.id.action_mention: {
Intent intent = new Intent(this, ComposeActivity.class);
intent.putExtra("mentioned_usernames", new String[] { loadedAccount.username });
startActivity(intent);
return true;
}
case R.id.action_open_in_web: {
Uri uri = Uri.parse(openInWebUrl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

View File

@ -105,7 +105,7 @@ class BlocksAdapter extends AccountAdapter {
void setupWithAccount(Account account) {
id = account.id;
displayName.setText(account.displayName);
displayName.setText(account.getDisplayName());
String format = username.getContext().getString(R.string.status_username_format);
String formattedUsername = String.format(format, account.username);
username.setText(formattedUsername);

View File

@ -95,7 +95,7 @@ class FollowAdapter extends AccountAdapter {
String format = username.getContext().getString(R.string.status_username_format);
String formattedUsername = String.format(format, account.username);
username.setText(formattedUsername);
displayName.setText(account.displayName);
displayName.setText(account.getDisplayName());
note.setText(account.note);
Context context = avatar.getContext();
Picasso.with(context)

View File

@ -20,6 +20,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.SystemClock;
@ -28,10 +29,18 @@ import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
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.widget.ImageView;
import android.widget.TextView;
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.mikepenz.google_material_typeface_library.GoogleMaterial;
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.SecondaryDrawerItem;
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.DrawerImageLoader;
import com.squareup.picasso.Picasso;
import java.util.List;
import java.util.Stack;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends BaseActivity {
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 boolean notificationServiceEnabled;
private String loggedInAccountId;
Stack<Integer> pageHistory = new Stack<>();
private String loggedInAccountUsername;
Stack<Integer> pageHistory = new Stack<Integer>();
private ViewPager viewPager;
private AccountHeader headerResult;
private Drawer drawer;
@ -126,13 +139,9 @@ public class MainActivity extends BaseActivity {
long drawerItemIdentifier = drawerItem.getIdentifier();
if (drawerItemIdentifier == 0) {
if (loggedInAccountId != null) {
Intent intent = new Intent(MainActivity.this, AccountActivity.class);
intent.putExtra("id", loggedInAccountId);
startActivity(intent);
} else {
Log.e(TAG, "Logged-in account id was not obtained yet when profile was opened.");
}
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);
startActivity(intent);
@ -165,12 +174,76 @@ public class MainActivity extends BaseActivity {
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.
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
String[] pageTitles = {
getString(R.string.title_home),
getString(R.string.title_notifications),
getString(R.string.title_public)
getString(R.string.title_home),
getString(R.string.title_notifications),
getString(R.string.title_public)
};
adapter.setPageTitles(pageTitles);
viewPager = (ViewPager) findViewById(R.id.pager);
@ -234,6 +307,13 @@ public class MainActivity extends BaseActivity {
SharedPreferences preferences = getSharedPreferences(
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
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>() {
@Override
@ -250,12 +330,12 @@ public class MainActivity extends BaseActivity {
headerResult.addProfiles(
new ProfileDrawerItem()
.withName(me.displayName)
.withName(me.getDisplayName())
.withEmail(String.format("%s@%s", me.username, domain))
.withIcon(me.avatar)
);
loggedInAccountId = me.id;
onFetchUserInfoSuccess(me.id, me.username);
}
@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) {
Log.e(TAG, "Failed to fetch user info. " + exception.getMessage());
}
@ -280,4 +371,4 @@ public class MainActivity extends BaseActivity {
viewPager.setCurrentItem(pageHistory.lastElement());
}
}
}
}

View File

@ -96,13 +96,13 @@ class NotificationsAdapter extends RecyclerView.Adapter implements AdapterItemRe
case FAVOURITE:
case REBLOG: {
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
holder.setMessage(type, notification.account.displayName,
holder.setMessage(type, notification.account.getDisplayName(),
notification.status);
break;
}
case FOLLOW: {
FollowViewHolder holder = (FollowViewHolder) viewHolder;
holder.setMessage(notification.account.displayName, notification.account.username,
holder.setMessage(notification.account.getDisplayName(), notification.account.username,
notification.account.avatar);
holder.setupButtons(followListener, notification.account.id);
break;

View File

@ -119,7 +119,7 @@ public class PullNotificationService extends IntentService {
if (status != null) {
MentionResult mention = new MentionResult();
mention.content = status.content.toString();
mention.displayName = notification.account.displayName;
mention.displayName = notification.account.getDisplayName();
mention.avatarUrl = status.account.avatar;
mentions.add(mention);
}

View File

@ -17,6 +17,7 @@ package com.keylesspalace.tusky;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
@ -25,6 +26,8 @@ import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -45,6 +48,11 @@ public class ReportActivity extends BaseActivity {
private View anyView; // what Snackbar will use to find the root view
private ReportAdapter adapter;
private boolean reportAlreadyInFlight;
private String accountId;
private String accountUsername;
private String statusId;
private String statusContent;
private EditText comment;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -52,10 +60,10 @@ public class ReportActivity extends BaseActivity {
setContentView(R.layout.activity_report);
Intent intent = getIntent();
final String accountId = intent.getStringExtra("account_id");
String accountUsername = intent.getStringExtra("account_username");
String statusId = intent.getStringExtra("status_id");
String statusContent = intent.getStringExtra("status_content");
accountId = intent.getStringExtra("account_id");
accountUsername = intent.getStringExtra("account_username");
statusId = intent.getStringExtra("status_id");
statusContent = intent.getStringExtra("status_content");
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
@ -64,6 +72,8 @@ public class ReportActivity extends BaseActivity {
String title = String.format(getString(R.string.report_username_format),
accountUsername);
bar.setTitle(title);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDisplayShowHomeEnabled(true);
}
anyView = toolbar;
@ -85,28 +95,28 @@ public class ReportActivity extends BaseActivity {
HtmlUtils.fromHtml(statusContent), true);
adapter.addItem(reportStatus);
final EditText comment = (EditText) findViewById(R.id.report_comment);
Button send = (Button) findViewById(R.id.report_send);
comment = (EditText) findViewById(R.id.report_comment);
reportAlreadyInFlight = false;
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (reportAlreadyInFlight) {
return;
}
String[] statusIds = adapter.getCheckedStatusIds();
if (statusIds.length > 0) {
reportAlreadyInFlight = true;
sendReport(accountId, statusIds, comment.getText().toString());
} else {
comment.setError(getString(R.string.error_report_too_few_statuses));
}
}
});
fetchRecentStatuses(accountId);
}
private void onClickSend() {
if (reportAlreadyInFlight) {
return;
}
String[] statusIds = adapter.getCheckedStatusIds();
if (statusIds.length > 0) {
reportAlreadyInFlight = true;
sendReport(accountId, statusIds, comment.getText().toString());
} else {
comment.setError(getString(R.string.error_report_too_few_statuses));
}
}
private void sendReport(final String accountId, final String[] statusIds,
final String comment) {
mastodonAPI.report(accountId, Arrays.asList(statusIds), comment).enqueue(new Callback<ResponseBody>() {
@ -167,4 +177,25 @@ public class ReportActivity extends BaseActivity {
private void onFetchStatusesFailure(Exception exception) {
Log.e(TAG, "Failed to fetch recent statuses to report. " + exception.getMessage());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.report_toolbar, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home: {
onBackPressed();
return true;
}
case R.id.action_report: {
onClickSend();
return true;
}
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -343,14 +343,14 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
void setupWithStatus(Status status, StatusActionListener listener) {
Status realStatus = status.getActionableStatus();
setDisplayName(realStatus.account.displayName);
setDisplayName(realStatus.account.getDisplayName());
setUsername(realStatus.account.username);
setCreatedAt(realStatus.createdAt);
setContent(realStatus.content, realStatus.mentions, listener);
setAvatar(realStatus.account.avatar);
setReblogged(realStatus.reblogged);
setFavourited(realStatus.favourited);
String rebloggedByDisplayName = status.account.displayName;
String rebloggedByDisplayName = status.account.getDisplayName();
if (status.reblog == null) {
hideRebloggedByDisplayName();
} else {

View File

@ -15,13 +15,18 @@
package com.keylesspalace.tusky.entity;
import android.os.Parcel;
import android.text.Spanned;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.google.gson.annotations.SerializedName;
public class Account {
public class Account implements SearchSuggestion {
public String id;
@SerializedName("username")
public String localUsername;
@SerializedName("acct")
public String username;
@ -62,4 +67,47 @@ public class Account {
Account account = (Account) other;
return account.id.equals(this.id);
}
public String getDisplayName() {
if (displayName.length() == 0) {
return localUsername;
}
return displayName;
}
@Override
public String getBody() {
return username;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
public Account() {
}
protected Account(Parcel in) {
}
public static final Creator<Account> CREATOR = new Creator<Account>() {
@Override
public Account createFromParcel(Parcel source) {
return new Account(source);
}
@Override
public Account[] newArray(int size) {
return new Account[size];
}
};
}

View File

@ -1,51 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="@style/AppTheme.Account.AppBarLayout"
app:popupTheme="@style/AppTheme.Account.ToolbarPopupTheme.Dark"
android:background="?attr/toolbar_background_color" />
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="@style/AppTheme.Account.AppBarLayout"
app:popupTheme="@style/AppTheme.Account.ToolbarPopupTheme.Dark"
android:background="?attr/toolbar_background_color" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:id="@+id/report_recycler_view"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:background="?attr/report_status_background_color" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:id="@+id/report_recycler_view"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:background="?attr/report_status_background_color" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/report_comment"
android:inputType="textMultiLine"
android:gravity="top|start"
android:ems="10"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:hint="@string/report_comment_hint" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="@+id/report_send"
android:text="@string/action_report" />
</RelativeLayout>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/report_comment"
android:inputType="textMultiLine"
android:gravity="top|start"
android:background="@android:color/transparent"
android:ems="10"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:hint="@string/report_comment_hint" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -2,6 +2,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_mention"
android:title="@string/action_mention"
app:showAsAction="never" />
<item android:id="@+id/action_open_in_web"
android:title="@string/action_open_in_web"
app:showAsAction="never" />

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_report"
android:title="@string/action_report"
android:icon="@drawable/ic_send_24dp"
app:showAsAction="always"/>
</menu>

View File

@ -54,7 +54,7 @@
<string name="notification_favourite_format">%s favourited your status</string>
<string name="notification_follow_format">%s followed you</string>
<string name="report_username_format">Reporting @%s</string>
<string name="report_username_format">Report @%s</string>
<string name="report_comment_hint">Additional comments?</string>
<string name="action_compose">Compose</string>
@ -128,5 +128,6 @@
<string name="error_muting">That user wasn\'t muted.</string>
<string name="search">Search accounts…</string>
<string name="toggle_nsfw">NSFW</string>
<string name="action_mention">Mention</string>
</resources>

View File

@ -53,8 +53,8 @@
<item name="compose_content_warning_bar_background">@drawable/border_background_dark</item>
<item name="notification_content">@color/notification_content_faded_dark</item>
<item name="notification_icon_tint">@color/notification_icon_tint_dark</item>
<item name="report_status_background_color">@color/report_status_background_dark</item>
<item name="report_status_divider_drawable">@drawable/report_status_divider_dark</item>
<item name="report_status_background_color">@color/color_background_dark</item>
<item name="report_status_divider_drawable">@drawable/status_divider_dark</item>
<item name="material_drawer_background">@color/window_background_dark</item>
<item name="material_drawer_primary_text">@color/text_color_primary_dark</item>