Fix decoder

This commit is contained in:
kyori19 2019-12-01 00:48:54 +09:00
parent 704b4e6d2e
commit fdc45aac9c
3 changed files with 10 additions and 4 deletions

View File

@ -70,6 +70,8 @@ import com.mikepenz.materialdrawer.model.interfaces.IProfile;
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
@ -480,7 +482,11 @@ public final class MainActivity extends BottomSheetActivity implements ActionBut
TabLayout.Tab tab = tabLayout.newTab()
.setIcon(tabs.get(i).getIcon());
if (tabs.get(i).getId().equals(TabDataKt.LIST)) {
tab.setContentDescription(tabs.get(i).getArguments().get(1));
try {
tab.setContentDescription(URLDecoder.decode(tabs.get(i).getArguments().get(1), "UTF-8"));
} catch (UnsupportedEncodingException e) {
Log.e("MainActivity", "failed to decode title", e);
}
} else {
tab.setContentDescription(tabs.get(i).getText());
}

View File

@ -21,7 +21,6 @@ import androidx.fragment.app.Fragment
import com.keylesspalace.tusky.components.conversation.ConversationsFragment
import com.keylesspalace.tusky.fragment.NotificationsFragment
import com.keylesspalace.tusky.fragment.TimelineFragment
import java.net.URLDecoder
/** this would be a good case for a sealed class, but that does not work nice with Room */
@ -47,7 +46,7 @@ fun createTabDataFromId(id: String, arguments: List<String> = emptyList()): TabD
FEDERATED -> TabData(FEDERATED, R.string.title_public_federated, R.drawable.ic_public_24dp, { TimelineFragment.newInstance(TimelineFragment.Kind.PUBLIC_FEDERATED) })
DIRECT -> TabData(DIRECT, R.string.title_direct_messages, R.drawable.reblog_direct_dark, { ConversationsFragment.newInstance() })
HASHTAG -> TabData(HASHTAG, R.string.hashtag, R.drawable.ic_hashtag, { args -> TimelineFragment.newInstance(TimelineFragment.Kind.TAG, args.getOrNull(0).orEmpty()) }, arguments)
LIST -> TabData(LIST, R.string.list, R.drawable.ic_list, { args -> TimelineFragment.newInstance(TimelineFragment.Kind.LIST, args.getOrNull(0).orEmpty()) }, arguments.map { URLDecoder.decode(it, "UTF-8") })
LIST -> TabData(LIST, R.string.list, R.drawable.ic_list, { args -> TimelineFragment.newInstance(TimelineFragment.Kind.LIST, args.getOrNull(0).orEmpty()) }, arguments)
else -> throw IllegalArgumentException("unknown tab type")
}
}

View File

@ -28,6 +28,7 @@ import com.keylesspalace.tusky.util.ThemeUtils
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.show
import kotlinx.android.synthetic.main.item_tab_preference.view.*
import java.net.URLDecoder
interface ItemInteractionListener {
@ -59,7 +60,7 @@ class TabAdapter(private var data: List<TabData>,
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val context = holder.itemView.context
if (!small && data[position].id == LIST) {
holder.itemView.textView.text = data[position].arguments.getOrNull(1).orEmpty()
holder.itemView.textView.text = URLDecoder.decode(data[position].arguments.getOrNull(1).orEmpty(), "UTF-8")
} else {
holder.itemView.textView.setText(data[position].text)
}