Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature_collapse_…
Browse files Browse the repository at this point in the history
…status
  • Loading branch information
HellPie committed Sep 13, 2018
2 parents 16ceb60 + 7134423 commit 623cad2
Show file tree
Hide file tree
Showing 25 changed files with 318 additions and 502 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Translate - with Stringlate](https://img.shields.io/badge/translate%20with-stringlate-green.svg)](https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgit.luolix.top%2Ftuskyapp%2FTusky) [![Build Status](https://app.bitrise.io/app/55b2f0c77c4bba74/status.svg?token=elUl9fieM5K34iLRL0rpoA&branch=master)](https://app.bitrise.io/app/55b2f0c77c4bba74) [![CircleCI](https://circleci.com/gh/tuskyapp/Tusky.svg?style=svg)](https://circleci.com/gh/tuskyapp/Tusky)
[![Translate - with Stringlate](https://img.shields.io/badge/translate%20with-stringlate-green.svg)](https://lonamiwebs.github.io/stringlate/translate?git=https%3A%2F%2Fgit.luolix.top%2Ftuskyapp%2FTusky) [![Build Status](https://app.bitrise.io/app/a3e773c3c57a894c/status.svg?token=qLu_Ti4Gp2LWcYT4eo2INQ&branch=master)](https://app.bitrise.io/app/a3e773c3c57a894c#/builds) [![CircleCI](https://circleci.com/gh/tuskyapp/Tusky.svg?style=svg)](https://circleci.com/gh/tuskyapp/Tusky)
# Tusky

![](/fastlane/metadata/android/en-US/images/icon.png)
Expand Down
20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

def getGitSha = { ->
def stdout = new ByteArrayOutputStream()
Expand All @@ -19,8 +19,8 @@ android {
applicationId "com.keylesspalace.tusky"
minSdkVersion 19
targetSdkVersion 27
versionCode 48
versionName "3.0"
versionCode 49
versionName "3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
}
Expand Down Expand Up @@ -60,7 +60,7 @@ android {
}

ext.supportLibraryVersion = '27.1.1'
ext.daggerVersion = '2.16'
ext.daggerVersion = '2.17'


// if libraries are changed here, they should also be changed in LicenseActivity
Expand All @@ -82,13 +82,13 @@ dependencies {
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation 'com.github.connyduck:sparkbutton:1.0.1'
implementation 'com.github.chrisbanes:PhotoView:2.1.3'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
implementation('com.theartofdev.edmodo:android-image-cropper:2.7.0') {
exclude group: 'com.android.support'
}
implementation 'com.evernote:android-job:1.2.6'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// EmojiCompat
implementation "com.android.support:support-emoji:$supportLibraryVersion"
implementation "com.android.support:support-emoji-appcompat:$supportLibraryVersion"
Expand All @@ -111,8 +111,8 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
debugImplementation 'im.dino:dbinspector:3.4.1@aar'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.uber.autodispose:autodispose-android-archcomponents:0.8.0'
implementation 'com.uber.autodispose:autodispose-kotlin:0.8.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.uber.autodispose:autodispose-android-archcomponents:1.0.0-RC2'
implementation 'com.uber.autodispose:autodispose-ktx:1.0.0-RC2'
}
32 changes: 27 additions & 5 deletions app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.arch.lifecycle.Lifecycle;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
Expand Down Expand Up @@ -135,12 +136,20 @@
import javax.inject.Inject;

import at.connyduck.sparkbutton.helpers.Utils;
import io.reactivex.Single;
import io.reactivex.SingleObserver;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.uber.autodispose.AutoDispose.autoDisposable;
import static com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider.from;

public final class ComposeActivity
extends BaseActivity
implements ComposeOptionsListener,
Expand Down Expand Up @@ -1121,11 +1130,24 @@ private void makeCaptionDialog(QueuedMedia item) {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

Picasso.with(this)
.load(item.uri)
.resize(displayMetrics.widthPixels, displayMetrics.heightPixels)
.onlyScaleDown()
.into(imageView);
Single.fromCallable(() ->
MediaUtils.getSampledBitmap(getContentResolver(), item.uri, displayMetrics.widthPixels, displayMetrics.heightPixels))
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
.subscribe(new SingleObserver<Bitmap>() {
@Override
public void onSubscribe(Disposable d) {}

@Override
public void onSuccess(Bitmap bitmap) {
imageView.setImageBitmap(bitmap);
}

@Override
public void onError(Throwable e) { }
});


int margin = Utils.dpToPx(this, 4);
dialogLayout.addView(imageView);
Expand Down
21 changes: 12 additions & 9 deletions app/src/main/java/com/keylesspalace/tusky/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private void changeAccount(long newSelectedId) {

Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityWithSlideInAnimation(intent);
startActivity(intent);
finishWithoutSlideOutAnimation();

overridePendingTransition(R.anim.explode, R.anim.explode);
Expand Down Expand Up @@ -510,28 +510,31 @@ private void updateProfiles() {

List<AccountEntity> allAccounts = accountManager.getAllAccountsOrderedByActive();

// reuse the already existing "add account" item
List<IProfile> profiles = new ArrayList<>(allAccounts.size()+1);
for (IProfile profile: headerResult.getProfiles()) {
if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
profiles.add(profile);
break;
}
}

for (AccountEntity acc : allAccounts) {
CharSequence emojifiedName = CustomEmojiHelper.emojifyString(acc.getDisplayName(), acc.getEmojis(), headerResult.getView());
emojifiedName = EmojiCompat.get().process(emojifiedName);

profiles.add(0,
profiles.add(
new ProfileDrawerItem()
.withSetSelected(acc.isActive())
.withName(emojifiedName)
.withIcon(acc.getProfilePictureUrl())
.withNameShown(true)
.withIdentifier(acc.getId())
.withEmail(acc.getFullName()));

}

// reuse the already existing "add account" item
for (IProfile profile: headerResult.getProfiles()) {
if (profile.getIdentifier() == DRAWER_ITEM_ADD_ACCOUNT) {
profiles.add(profile);
break;
}
}
headerResult.clear();
headerResult.setProfiles(profiles);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.keylesspalace.tusky.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

Expand All @@ -26,55 +27,40 @@
import java.util.List;

public abstract class AccountAdapter extends RecyclerView.Adapter {
static final int VIEW_TYPE_ACCOUNT = 0;
static final int VIEW_TYPE_FOOTER = 1;


List<Account> accountList;
AccountActionListener accountActionListener;
FooterViewHolder.State footerState;

private String topId;
private String bottomId;
private boolean bottomLoading;

AccountAdapter(AccountActionListener accountActionListener) {
super();
accountList = new ArrayList<>();
this.accountList = new ArrayList<>();
this.accountActionListener = accountActionListener;
footerState = FooterViewHolder.State.END;
bottomLoading = false;
}

@Override
public int getItemCount() {
return accountList.size() + 1;
return accountList.size() + (bottomLoading ? 1 : 0);
}

public void update(@Nullable List<Account> newAccounts, @Nullable String fromId,
@Nullable String uptoId) {
if (newAccounts == null || newAccounts.isEmpty()) {
return;
}

bottomId = fromId;
topId = uptoId;

if (accountList.isEmpty()) {
accountList = ListUtils.removeDuplicates(newAccounts);
@Override
public int getItemViewType(int position) {
if (position == accountList.size() && bottomLoading) {
return VIEW_TYPE_FOOTER;
} else {
int index = accountList.indexOf(newAccounts.get(newAccounts.size() - 1));
for (int i = 0; i < index; i++) {
accountList.remove(0);
}
int newIndex = newAccounts.indexOf(accountList.get(0));
if (newIndex == -1) {
accountList.addAll(0, newAccounts);
} else {
accountList.addAll(0, newAccounts.subList(0, newIndex));
}
return VIEW_TYPE_ACCOUNT;
}
}

public void update(@NonNull List<Account> newAccounts) {
accountList = ListUtils.removeDuplicates(newAccounts);
notifyDataSetChanged();
}

public void addItems(List<Account> newAccounts, @Nullable String fromId) {
if (fromId != null) {
bottomId = fromId;
}
public void addItems(List<Account> newAccounts) {
int end = accountList.size();
Account last = accountList.get(end - 1);
if (last != null && !findAccount(newAccounts, last.getId())) {
Expand All @@ -83,6 +69,19 @@ public void addItems(List<Account> newAccounts, @Nullable String fromId) {
}
}

public void setBottomLoading(boolean loading) {
boolean wasLoading = bottomLoading;
if(wasLoading == loading) {
return;
}
bottomLoading = loading;
if(loading) {
notifyItemInserted(accountList.size());
} else {
notifyItemRemoved(accountList.size());
}
}

private static boolean findAccount(List<Account> accounts, String id) {
for (Account account : accounts) {
if (account.getId().equals(id)) {
Expand Down Expand Up @@ -110,25 +109,5 @@ public void addItem(Account account, int position) {
notifyItemInserted(position);
}

@Nullable
public Account getItem(int position) {
if (position >= 0 && position < accountList.size()) {
return accountList.get(position);
}
return null;
}

public void setFooterState(FooterViewHolder.State newFooterState) {
footerState = newFooterState;
}

@Nullable
public String getBottomId() {
return bottomId;
}

@Nullable
public String getTopId() {
return topId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import com.squareup.picasso.Picasso;

public class BlocksAdapter extends AccountAdapter {
private static final int VIEW_TYPE_BLOCKED_USER = 0;
private static final int VIEW_TYPE_FOOTER = 1;

public BlocksAdapter(AccountActionListener accountActionListener) {
super(accountActionListener);
Expand All @@ -43,37 +41,25 @@ public BlocksAdapter(AccountActionListener accountActionListener) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
default:
case VIEW_TYPE_BLOCKED_USER: {
case VIEW_TYPE_ACCOUNT: {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_blocked_user, parent, false);
return new BlockedUserViewHolder(view);
}
case VIEW_TYPE_FOOTER: {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_footer, parent, false);
return new FooterViewHolder(view);
return new LoadingFooterViewHolder(view);
}
}
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (position < accountList.size()) {
if (getItemViewType(position) == VIEW_TYPE_ACCOUNT) {
BlockedUserViewHolder holder = (BlockedUserViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
holder.setupActionListener(accountActionListener);
} else {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(footerState);
}
}

@Override
public int getItemViewType(int position) {
if (position == accountList.size()) {
return VIEW_TYPE_FOOTER;
} else {
return VIEW_TYPE_BLOCKED_USER;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

/** Both for follows and following lists. */
public class FollowAdapter extends AccountAdapter {
private static final int VIEW_TYPE_ACCOUNT = 0;
private static final int VIEW_TYPE_FOOTER = 1;

public FollowAdapter(AccountActionListener accountActionListener) {
super(accountActionListener);
Expand All @@ -46,29 +44,18 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
case VIEW_TYPE_FOOTER: {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_footer, parent, false);
return new FooterViewHolder(view);
return new LoadingFooterViewHolder(view);
}
}
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (position < accountList.size()) {
if (getItemViewType(position) == VIEW_TYPE_ACCOUNT) {
AccountViewHolder holder = (AccountViewHolder) viewHolder;
holder.setupWithAccount(accountList.get(position));
holder.setupActionListener(accountActionListener);
} else {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(footerState);
}
}

@Override
public int getItemViewType(int position) {
if (position == accountList.size()) {
return VIEW_TYPE_FOOTER;
} else {
return VIEW_TYPE_ACCOUNT;
}
}
}
Loading

0 comments on commit 623cad2

Please sign in to comment.