Skip to content

Commit

Permalink
Merge branch 'maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed May 25, 2020
2 parents 78747e4 + 85e3d3f commit be402dd
Show file tree
Hide file tree
Showing 504 changed files with 37,473 additions and 35,043 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# How To Contribute #

First of all, I'd like to express my appreciation to you for contributing to this project.

## Working Branch ##

You should make changes on `develop` branch, changes will be merged into `master` branch after a stable version released.
You should make changes on the `maintenance` branch, changes will be merged into `master` branch after a stable version released.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {
allprojects {
ext {
projectGroupId = 'org.mariotaku.twidere'
projectVersionCode = 511
projectVersionName = '4.1.2'
projectVersionCode = 512
projectVersionName = '4.1.3'

globalCompileSdkVersion = 29
globalBuildToolsVersion = "29.0.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ public interface StatusesResources {

@POST("/v1/statuses/{id}/unfavourite")
Status unfavouriteStatus(@Path("id") String id) throws MicroBlogException;

@POST("/v1/statuses/{id}/pin")
Status pinStatus(@Path("id") String id) throws MicroBlogException;

@POST("/v1/statuses/{id}/unpin")
Status unpinStatus(@Path("id") String id) throws MicroBlogException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public class Status {
*/
@JsonField(name = "sensitive")
boolean sensitive;
/**
* Whether the authenticated user has pinned the status
*/
@JsonField(name = "pinned")
boolean pinned;
/**
* If not empty, warning text that should be displayed before the actual content
*/
Expand Down Expand Up @@ -194,6 +199,10 @@ public boolean isSensitive() {
return sensitive;
}

public boolean isPinned() {
return pinned;
}

public String getSpoilerText() {
return spoilerText;
}
Expand Down Expand Up @@ -251,6 +260,7 @@ public String toString() {
", reblogged=" + reblogged +
", favourited=" + favourited +
", sensitive=" + sensitive +
", pinned=" + pinned +
", spoilerText='" + spoilerText + '\'' +
", visibility='" + visibility + '\'' +
", mediaAttachments=" + Arrays.toString(mediaAttachments) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String TWITTER_CONSUMER_KEY = "wmtrtTaVOjUnH5pWQp4LDI5Qs";
String TWITTER_CONSUMER_SECRET = "E9Q9u2yK0COJae2tLcNEdY75OPA3bxqJiGZQztraHaQUtoI2cu";

String YANDEX_KEY = "trnsl.1.1.20200513T065609Z.8e72845b632aa04f.fe1297e42c152de9e8773e1bc71162b1e498e2a8";

String DEFAULT_TWITTER_API_URL_FORMAT = "https://[DOMAIN].twitter.com/";

String SCHEME_HTTP = "http";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ public interface SharedPreferenceConstants {
String KEY_OVERRIDE_LANGUAGE = "override_language";
@ExportablePreference(STRING)
String KEY_TAB_POSITION = "tab_position";
@ExportablePreference(STRING)
String KEY_YANDEX_KEY = "yandex_key";
@ExportablePreference(BOOLEAN)
String KEY_AUTO_HIDE_TABS = "auto_hide_tabs";
@ExportablePreference(BOOLEAN)
String KEY_HIDE_CARD_NUMBERS = "hide_card_numbers";

// Internal preferences

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static TabExtras parse(@NonNull @CustomTabType String type, @Nullable Str
case CustomTabType.NOTIFICATIONS_TIMELINE: {
return LoganSquare.parse(json, InteractionsTabExtras.class);
}
case CustomTabType.LIST_TIMELINE:
case CustomTabType.HOME_TIMELINE: {
return LoganSquare.parse(json, HomeTabExtras.class);
}
Expand Down
21 changes: 21 additions & 0 deletions twidere/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ android {

}

task buildTranslationArray {
def foundLocales = new StringBuilder()
foundLocales.append("new String[]{")

fileTree("src/main/res-localized").visit { FileVisitDetails details ->
if(details.file.path.endsWith("strings.xml")){
def languageCode = details.file.parentFile.name.replaceAll('values-','').replaceAll('-r','-')
languageCode = (languageCode == "values") ? "en" : languageCode;
foundLocales.append("\"").append(languageCode).append("\"").append(",")
}
}

foundLocales.append("}")
//Don't forget to remove the trailing comma
def foundLocalesString = foundLocales.toString().replaceAll(',}','}')
android.defaultConfig.buildConfigField "String[]", "TRANSLATION_ARRAY", foundLocalesString
}

preBuild.dependsOn buildTranslationArray


tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import android.text.TextUtils;
import androidx.fragment.app.Fragment;

import org.mariotaku.library.objectcursor.ObjectCursor;
import org.mariotaku.twidere.Constants;
Expand Down Expand Up @@ -156,6 +157,7 @@ public static TabExtras newTabExtras(@NonNull @CustomTabType String type) {
case CustomTabType.NOTIFICATIONS_TIMELINE: {
return new InteractionsTabExtras();
}
case CustomTabType.LIST_TIMELINE:
case CustomTabType.HOME_TIMELINE: {
return new HomeTabExtras();
}
Expand Down
11 changes: 11 additions & 0 deletions twidere/src/main/java/org/mariotaku/yandex/YandexAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.mariotaku.yandex

import org.mariotaku.restfu.annotation.method.POST
import org.mariotaku.restfu.annotation.param.Query
import org.mariotaku.yandex.model.YandexTranslateResult

interface YandexAPI {
@POST("/api/v1.5/tr.json/translate")
fun search(@Query("text") text: String,
@Query("lang") lang: String): YandexTranslateResult
}
50 changes: 50 additions & 0 deletions twidere/src/main/java/org/mariotaku/yandex/YandexAPIFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.mariotaku.yandex

import org.mariotaku.restfu.RestAPIFactory
import org.mariotaku.restfu.RestConverter
import org.mariotaku.restfu.RestMethod
import org.mariotaku.restfu.RestRequest
import org.mariotaku.restfu.http.Endpoint
import org.mariotaku.restfu.http.RestHttpClient
import org.mariotaku.restfu.http.ValueMap
import org.mariotaku.restfu.logansqaure.LoganSquareConverterFactory


class YandexAPIFactory(apiKey: String, endpoint: String) {
private val factory: RestAPIFactory<YandexException> = RestAPIFactory<YandexException>()

init {
factory.setEndpoint(Endpoint(endpoint))
factory.setExceptionFactory { cause, request, response ->
cause?.let { YandexException(it) }
?: YandexException()
}
factory.setRestConverterFactory(LoganSquareConverterFactory())
factory.setRestRequestFactory(object : RestRequest.DefaultFactory<YandexException?>() {
override fun create(restMethod: RestMethod<YandexException?>,
factory: RestConverter.Factory<YandexException?>, valuePool: ValueMap?): RestRequest {
val method = restMethod.method
val path = restMethod.path
val headers = restMethod.getHeaders(valuePool)
val queries = restMethod.getQueries(valuePool)
val params = restMethod.getParams(factory, valuePool)
val rawValue = restMethod.rawValue
val bodyType = restMethod.bodyType
val extras = restMethod.extras
queries.add("key", apiKey)
return RestRequest(method.value, method.allowBody, path, headers, queries,
params, rawValue, bodyType, extras)
}
})
}

fun setHttpClient(restClient: RestHttpClient): YandexAPIFactory {
factory.setHttpClient(restClient)
return this
}

fun build(): YandexAPI {
return factory.build(YandexAPI::class.java)
}
}

8 changes: 8 additions & 0 deletions twidere/src/main/java/org/mariotaku/yandex/YandexException.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.mariotaku.yandex

class YandexException : Exception {
constructor() : super()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.mariotaku.yandex.model

import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject

@JsonObject
data class YandexTranslateResult(
@JsonField(name = ["code"])
var code: Int? = null,
@JsonField(name = ["lang"])
var lang: String? = null,
@JsonField(name = ["text"])
var text: List<String>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp

override fun getSystemWindowInsets(caller: Fragment, insets: Rect): Boolean {
if (caller === leftDrawerFragment) return super.getSystemWindowInsets(caller, insets)
if (mainTabs == null || homeContent == null) return false
if (mainTabs == null || homeContent == null || toolbar == null || !toolbar.isVisible) return false
val height = mainTabs.height
if (preferences[tabPositionKey] == SharedPreferenceConstants.VALUE_TAB_POSITION_TOP) {
if (height != 0) {
Expand Down Expand Up @@ -589,7 +589,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp

override var controlBarOffset: Float
get() {
if (mainTabs.columns > 1) {
if (mainTabs.columns > 1 || !toolbar.isVisible) {
val lp = actionsButton.layoutParams
val total: Float
total = if (lp is MarginLayoutParams) {
Expand All @@ -608,7 +608,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
set(offset) {
if (preferences[tabPositionKey] == SharedPreferenceConstants.VALUE_TAB_POSITION_TOP) {
val translationY = if (mainTabs.columns > 1) {
val translationY = if (mainTabs.columns > 1 || !toolbar.isVisible) {
0
} else {
(controlBarHeight * (offset - 1)).toInt()
Expand All @@ -623,7 +623,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
}
notifyControlBarOffsetChanged()
} else {
val translationY = if (mainTabs.columns > 1) {
val translationY = if (mainTabs.columns > 1 || !toolbar.isVisible) {
0
} else {
(toolbar.height * (offset - 1)).toInt()
Expand Down Expand Up @@ -855,7 +855,12 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
pagerAdapter.hasMultipleColumns = false
mainTabs.columns = 1
}
if (preferences[tabPositionKey] == SharedPreferenceConstants.VALUE_TAB_POSITION_TOP) {
if (pagerAdapter.count == 1 && preferences[autoHideTabs]) {
toolbar.isVisible = false
actionsButton.updateLayoutParams<RelativeLayout.LayoutParams> {
addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE)
}
} else if (preferences[tabPositionKey] == SharedPreferenceConstants.VALUE_TAB_POSITION_TOP) {
toolbar.updateLayoutParams<RelativeLayout.LayoutParams> {
addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package org.mariotaku.twidere.adapter

import android.content.Context
import androidx.recyclerview.widget.RecyclerViewAccessor
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import androidx.recyclerview.widget.RecyclerViewAccessor
import com.bumptech.glide.RequestManager
import org.mariotaku.twidere.R
import org.mariotaku.twidere.model.AccountDetails
Expand Down Expand Up @@ -59,8 +59,9 @@ class AccountDetailsAdapter(

override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val view = super.getView(position, convertView, parent)
val showType = objects.groupBy { it.type }.count().let { it > 1 }
val holder = view.tag as? AccountViewHolder ?: run {
val h = AccountViewHolder(this, view)
val h = AccountViewHolder(this, view, showType)
view.tag = h
return@run h
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.bumptech.glide.RequestManager
import kotlinx.android.synthetic.main.list_item_simple_user.view.*
import org.mariotaku.ktextension.spannable
import org.mariotaku.twidere.R
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.extension.loadProfileImage
import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.UserKey
Expand Down Expand Up @@ -63,7 +64,12 @@ class AccountsSpinnerAdapter(
text1?.visibility = View.VISIBLE
text1?.spannable = item.user.name
text2?.visibility = View.VISIBLE
text2?.spannable = "@${item.user.screen_name}"
val showType = objects.filter { it.type != null }.groupBy { it.type }.count().let { it > 1 }
text2?.spannable = if (item.type == AccountType.MASTODON) {
item.account.name
} else {
"${if (showType) item.type else ""}@${item.user.screen_name}"
}
if (icon != null) {
if (profileImageEnabled) {
icon.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package org.mariotaku.twidere.adapter

import android.content.Context
import android.content.SharedPreferences
import android.util.SparseBooleanArray
import androidx.core.text.BidiFormatter
import androidx.recyclerview.widget.RecyclerView
import android.util.SparseBooleanArray
import com.bumptech.glide.RequestManager
import org.mariotaku.kpreferences.get
import org.mariotaku.twidere.R
Expand All @@ -13,8 +13,8 @@ import org.mariotaku.twidere.adapter.iface.IStatusesAdapter
import org.mariotaku.twidere.adapter.iface.IUserListsAdapter
import org.mariotaku.twidere.adapter.iface.IUsersAdapter
import org.mariotaku.twidere.constant.*
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.extension.model.activityStatus
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.util.AsyncTwitterWrapper
import org.mariotaku.twidere.util.TwidereLinkify
import org.mariotaku.twidere.util.UserColorNameManager
Expand Down Expand Up @@ -63,6 +63,8 @@ class DummyItemAdapter(

var showCardActions: Boolean = false

var showCardNumbers: Boolean = false

private var showingActionCardPosition = RecyclerView.NO_POSITION
private val showingFullTextStates = SparseBooleanArray()

Expand Down Expand Up @@ -98,6 +100,11 @@ class DummyItemAdapter(

override fun findStatusById(accountKey: UserKey, statusId: String) = null

override fun isCardNumbersShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardNumbers
return showCardNumbers || showingActionCardPosition == position
}

override fun isCardActionsShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardActions
return showCardActions || showingActionCardPosition == position
Expand Down Expand Up @@ -181,6 +188,7 @@ class DummyItemAdapter(
mediaPreviewEnabled = preferences[mediaPreviewKey]
sensitiveContentEnabled = preferences[displaySensitiveContentsKey]
showCardActions = !preferences[hideCardActionsKey]
showCardNumbers = !preferences[hideCardNumbersKey]
linkHighlightingStyle = preferences[linkHighlightOptionKey]
lightFont = preferences[lightFontKey]
useStarsForLikes = preferences[iWantMyStarsBackKey]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class ParcelableStatusesAdapter(
final override val mediaPreviewEnabled: Boolean = Utils.isMediaPreviewEnabled(context, preferences)
final override val sensitiveContentEnabled: Boolean = preferences.getBoolean(KEY_DISPLAY_SENSITIVE_CONTENTS, false)
private val showCardActions: Boolean = !preferences[hideCardActionsKey]
private val showCardNumbers: Boolean = !preferences[hideCardNumbersKey]

private val gapLoadingIds: MutableSet<ObjectId> = HashSet()

Expand Down Expand Up @@ -261,6 +262,11 @@ abstract class ParcelableStatusesAdapter(
}, def, raw)!!
}

override fun isCardNumbersShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardNumbers
return showCardNumbers || showingActionCardId == getItemId(position)
}

override fun isCardActionsShown(position: Int): Boolean {
if (position == RecyclerView.NO_POSITION) return showCardActions
return showCardActions || showingActionCardId == getItemId(position)
Expand Down
Loading

0 comments on commit be402dd

Please sign in to comment.