Changed visual theme to a dark style. Also, set up things for a future switchable light/dark theme.
This commit is contained in:
parent
3b52da66a2
commit
22a2a31afe
44 changed files with 377 additions and 230 deletions
|
@ -64,7 +64,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
setSupportActionBar(toolbar);
|
||||
|
||||
// Setup the tabs and timeline pager.
|
||||
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());
|
||||
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager(), this);
|
||||
String[] pageTitles = {
|
||||
getString(R.string.title_home),
|
||||
getString(R.string.title_notifications),
|
||||
|
@ -72,13 +72,18 @@ public class MainActivity extends AppCompatActivity {
|
|||
};
|
||||
adapter.setPageTitles(pageTitles);
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
|
||||
getResources().getDisplayMetrics());
|
||||
int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
|
||||
viewPager.setPageMargin(pageMargin);
|
||||
viewPager.setPageMarginDrawable(R.drawable.tab_page_margin);
|
||||
viewPager.setAdapter(adapter);
|
||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
for (int i = 0; i < tabLayout.getTabCount(); i++) {
|
||||
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
||||
if (tab != null) {
|
||||
tab.setCustomView(adapter.getTabView(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve notification update preference.
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Context;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
|
@ -47,7 +48,10 @@ public class NotificationsFragment extends SFragment implements
|
|||
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private EndlessOnScrollListener scrollListener;
|
||||
private NotificationsAdapter adapter;
|
||||
private TabLayout.OnTabSelectedListener onTabSelectedListener;
|
||||
|
||||
public static NotificationsFragment newInstance() {
|
||||
NotificationsFragment fragment = new NotificationsFragment();
|
||||
|
@ -69,14 +73,14 @@ public class NotificationsFragment extends SFragment implements
|
|||
// Setup the RecyclerView.
|
||||
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||
layoutManager = new LinearLayoutManager(context);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
DividerItemDecoration divider = new DividerItemDecoration(
|
||||
context, layoutManager.getOrientation());
|
||||
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.status_divider);
|
||||
divider.setDrawable(drawable);
|
||||
recyclerView.addItemDecoration(divider);
|
||||
EndlessOnScrollListener scrollListener = new EndlessOnScrollListener(layoutManager) {
|
||||
scrollListener = new EndlessOnScrollListener(layoutManager) {
|
||||
@Override
|
||||
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
|
||||
NotificationsAdapter adapter = (NotificationsAdapter) view.getAdapter();
|
||||
|
@ -92,11 +96,38 @@ public class NotificationsFragment extends SFragment implements
|
|||
adapter = new NotificationsAdapter(this, this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
||||
onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
jumpToTop();
|
||||
}
|
||||
};
|
||||
layout.addOnTabSelectedListener(onTabSelectedListener);
|
||||
|
||||
sendFetchNotificationsRequest();
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
|
||||
tabLayout.removeOnTabSelectedListener(onTabSelectedListener);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private void jumpToTop() {
|
||||
layoutManager.scrollToPosition(0);
|
||||
scrollListener.reset();
|
||||
}
|
||||
|
||||
private void sendFetchNotificationsRequest(final String fromId) {
|
||||
String endpoint = getString(R.string.endpoint_notifications);
|
||||
String url = "https://" + domain + endpoint;
|
||||
|
|
|
@ -182,7 +182,7 @@ public class PullNotificationService extends IntentService {
|
|||
mentions.get(0).displayName);
|
||||
}
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_notify_mention)
|
||||
.setSmallIcon(R.mipmap.ic_notify)
|
||||
.setContentTitle(title);
|
||||
if (icon != null) {
|
||||
builder.setLargeIcon(icon);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class SFragment extends Fragment {
|
|||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, error.getMessage());
|
||||
Log.e(TAG, "Request Failed: " + error.getMessage());
|
||||
}
|
||||
}) {
|
||||
@Override
|
||||
|
|
54
app/src/main/java/com/keylesspalace/tusky/StatusButton.java
Normal file
54
app/src/main/java/com/keylesspalace/tusky/StatusButton.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is part of Tusky.
|
||||
*
|
||||
* Tusky is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky. If not, see
|
||||
* <http://www.gnu.org/licenses/>. */
|
||||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.widget.AppCompatImageButton;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class StatusButton extends AppCompatImageButton {
|
||||
private static final int[] STATE_MARKED = { R.attr.state_marked };
|
||||
|
||||
private boolean marked;
|
||||
|
||||
public StatusButton(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
TypedArray array = context.getTheme().obtainStyledAttributes(
|
||||
attributeSet, R.styleable.StatusButton, 0, 0);
|
||||
try {
|
||||
marked = array.getBoolean(R.styleable.StatusButton_state_marked, false);
|
||||
} finally {
|
||||
array.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] onCreateDrawableState(int extraSpace) {
|
||||
if (marked) {
|
||||
extraSpace += 1;
|
||||
}
|
||||
int[] drawableState = super.onCreateDrawableState(extraSpace);
|
||||
if (marked) {
|
||||
mergeDrawableStates(drawableState, STATE_MARKED);
|
||||
}
|
||||
return drawableState;
|
||||
}
|
||||
|
||||
public void setMarked(boolean marked) {
|
||||
this.marked = marked;
|
||||
}
|
||||
}
|
|
@ -42,11 +42,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
private TextView sinceCreated;
|
||||
private TextView content;
|
||||
private NetworkImageView avatar;
|
||||
private ImageView boostedIcon;
|
||||
private TextView boostedByUsername;
|
||||
private View rebloggedBar;
|
||||
private TextView rebloggedByUsername;
|
||||
private ImageButton replyButton;
|
||||
private ImageButton reblogButton;
|
||||
private ImageButton favouriteButton;
|
||||
private StatusButton reblogButton;
|
||||
private StatusButton favouriteButton;
|
||||
private ImageButton moreButton;
|
||||
private boolean favourited;
|
||||
private boolean reblogged;
|
||||
|
@ -69,11 +69,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
avatar = (NetworkImageView) itemView.findViewById(R.id.status_avatar);
|
||||
avatar.setDefaultImageResId(R.drawable.avatar_default);
|
||||
avatar.setErrorImageResId(R.drawable.avatar_error);
|
||||
boostedIcon = (ImageView) itemView.findViewById(R.id.status_boosted_icon);
|
||||
boostedByUsername = (TextView) itemView.findViewById(R.id.status_boosted);
|
||||
rebloggedBar = itemView.findViewById(R.id.status_reblogged_bar);
|
||||
rebloggedByUsername = (TextView) itemView.findViewById(R.id.status_reblogged);
|
||||
replyButton = (ImageButton) itemView.findViewById(R.id.status_reply);
|
||||
reblogButton = (ImageButton) itemView.findViewById(R.id.status_reblog);
|
||||
favouriteButton = (ImageButton) itemView.findViewById(R.id.status_favourite);
|
||||
reblogButton = (StatusButton) itemView.findViewById(R.id.status_reblog);
|
||||
favouriteButton = (StatusButton) itemView.findViewById(R.id.status_favourite);
|
||||
moreButton = (ImageButton) itemView.findViewById(R.id.status_more);
|
||||
reblogged = false;
|
||||
favourited = false;
|
||||
|
@ -175,40 +175,34 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
public void setRebloggedByUsername(String name) {
|
||||
Context context = boostedByUsername.getContext();
|
||||
Context context = rebloggedByUsername.getContext();
|
||||
String format = context.getString(R.string.status_boosted_format);
|
||||
String boostedText = String.format(format, name);
|
||||
boostedByUsername.setText(boostedText);
|
||||
boostedIcon.setVisibility(View.VISIBLE);
|
||||
boostedByUsername.setVisibility(View.VISIBLE);
|
||||
rebloggedByUsername.setText(boostedText);
|
||||
rebloggedBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void hideRebloggedByUsername() {
|
||||
boostedIcon.setVisibility(View.GONE);
|
||||
boostedByUsername.setVisibility(View.GONE);
|
||||
rebloggedBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void setReblogged(boolean reblogged) {
|
||||
this.reblogged = reblogged;
|
||||
if (!reblogged) {
|
||||
reblogButton.setImageResource(R.drawable.ic_reblog_off);
|
||||
} else {
|
||||
reblogButton.setImageResource(R.drawable.ic_reblog_on);
|
||||
}
|
||||
reblogButton.setMarked(reblogged);
|
||||
}
|
||||
|
||||
public void disableReblogging() {
|
||||
reblogButton.setEnabled(false);
|
||||
reblogButton.setImageResource(R.drawable.ic_reblog_disabled);
|
||||
public void setRebloggingEnabled(boolean enabled) {
|
||||
reblogButton.setEnabled(enabled);
|
||||
if (enabled) {
|
||||
reblogButton.setImageResource(R.drawable.ic_reblog);
|
||||
} else {
|
||||
reblogButton.setImageResource(R.drawable.ic_reblog_disabled);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFavourited(boolean favourited) {
|
||||
this.favourited = favourited;
|
||||
if (!favourited) {
|
||||
favouriteButton.setImageResource(R.drawable.ic_favourite_off);
|
||||
} else {
|
||||
favouriteButton.setImageResource(R.drawable.ic_favourite_on);
|
||||
}
|
||||
favouriteButton.setMarked(favourited);
|
||||
}
|
||||
|
||||
public void setMediaPreviews(final Status.MediaAttachment[] attachments,
|
||||
|
@ -353,9 +347,7 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
hideSensitiveMediaWarning();
|
||||
}
|
||||
setupButtons(listener, position);
|
||||
if (status.getVisibility() == Status.Visibility.PRIVATE) {
|
||||
disableReblogging();
|
||||
}
|
||||
setRebloggingEnabled(status.getVisibility() != Status.Visibility.PRIVATE);
|
||||
if (status.getSpoilerText().isEmpty()) {
|
||||
hideSpoilerText();
|
||||
} else {
|
||||
|
|
|
@ -157,7 +157,7 @@ public class TimelineFragment extends SFragment implements
|
|||
}
|
||||
|
||||
private void jumpToTop() {
|
||||
layoutManager.scrollToPositionWithOffset(0, 0);
|
||||
layoutManager.scrollToPosition(0);
|
||||
scrollListener.reset();
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ public class TimelineFragment extends SFragment implements
|
|||
public void onFetchTimelineFailure(Exception exception) {
|
||||
setFetchTimelineState(FooterViewHolder.State.RETRY);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
Log.e(TAG, exception.getMessage());
|
||||
Log.e(TAG, "Fetch Failure: " + exception.getMessage());
|
||||
}
|
||||
|
||||
private void setFetchTimelineState(FooterViewHolder.State state) {
|
||||
|
|
|
@ -15,15 +15,21 @@
|
|||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class TimelinePagerAdapter extends FragmentPagerAdapter {
|
||||
private String[] pageTitles;
|
||||
private Context context;
|
||||
|
||||
public TimelinePagerAdapter(FragmentManager manager) {
|
||||
public TimelinePagerAdapter(FragmentManager manager, Context context) {
|
||||
super(manager);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setPageTitles(String[] titles) {
|
||||
|
@ -57,4 +63,11 @@ public class TimelinePagerAdapter extends FragmentPagerAdapter {
|
|||
public CharSequence getPageTitle(int position) {
|
||||
return pageTitles[position];
|
||||
}
|
||||
|
||||
public View getTabView(int position) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.tab_main, null);
|
||||
TextView title = (TextView) view.findViewById(R.id.title);
|
||||
title.setText(pageTitles[position]);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue