mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Convert UnderlineUtils to kotlin
This commit is contained in:
parent
ed4e333651
commit
238956788d
5 changed files with 29 additions and 50 deletions
|
|
@ -22,6 +22,7 @@ import fr.free.nrw.commons.utils.UnderlineUtils
|
||||||
import fr.free.nrw.commons.utils.UrlUtils.handleWebUrl
|
import fr.free.nrw.commons.utils.UrlUtils.handleWebUrl
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import fr.free.nrw.commons.utils.setUnderlinedText
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents about screen of this app
|
* Represents about screen of this app
|
||||||
|
|
@ -65,30 +66,12 @@ class AboutActivity : BaseActivity() {
|
||||||
binding!!.aboutImprove.setHtmlText(improveText)
|
binding!!.aboutImprove.setHtmlText(improveText)
|
||||||
binding!!.aboutVersion.text = applicationContext.getVersionNameWithSha()
|
binding!!.aboutVersion.text = applicationContext.getVersionNameWithSha()
|
||||||
|
|
||||||
UnderlineUtils.setUnderlinedText(
|
binding!!.aboutFaq.setUnderlinedText(R.string.about_faq)
|
||||||
binding!!.aboutFaq, R.string.about_faq,
|
binding!!.aboutRateUs.setUnderlinedText(R.string.about_rate_us)
|
||||||
applicationContext
|
binding!!.aboutUserGuide.setUnderlinedText(R.string.user_guide)
|
||||||
)
|
binding!!.aboutPrivacyPolicy.setUnderlinedText(R.string.about_privacy_policy)
|
||||||
UnderlineUtils.setUnderlinedText(
|
binding!!.aboutTranslate.setUnderlinedText(R.string.about_translate)
|
||||||
binding!!.aboutRateUs, R.string.about_rate_us,
|
binding!!.aboutCredits.setUnderlinedText(R.string.about_credits)
|
||||||
applicationContext
|
|
||||||
)
|
|
||||||
UnderlineUtils.setUnderlinedText(
|
|
||||||
binding!!.aboutUserGuide, R.string.user_guide,
|
|
||||||
applicationContext
|
|
||||||
)
|
|
||||||
UnderlineUtils.setUnderlinedText(
|
|
||||||
binding!!.aboutPrivacyPolicy, R.string.about_privacy_policy,
|
|
||||||
applicationContext
|
|
||||||
)
|
|
||||||
UnderlineUtils.setUnderlinedText(
|
|
||||||
binding!!.aboutTranslate, R.string.about_translate,
|
|
||||||
applicationContext
|
|
||||||
)
|
|
||||||
UnderlineUtils.setUnderlinedText(
|
|
||||||
binding!!.aboutCredits, R.string.about_credits,
|
|
||||||
applicationContext
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
To set listeners, we can create a separate method and use lambda syntax.
|
To set listeners, we can create a separate method and use lambda syntax.
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
||||||
if (position == PAGE_LAYOUTS.length - 1) {
|
if (position == PAGE_LAYOUTS.length - 1) {
|
||||||
// Add link to more information
|
// Add link to more information
|
||||||
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
|
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
|
||||||
UnderlineUtils.setUnderlinedText(moreInfo, R.string.welcome_help_button_text, container.getContext());
|
UnderlineUtils.setUnderlinedText(moreInfo, R.string.welcome_help_button_text);
|
||||||
moreInfo.setOnClickListener(view -> UrlUtils.handleWebUrl(
|
moreInfo.setOnClickListener(view -> UrlUtils.handleWebUrl(
|
||||||
container.getContext(),
|
container.getContext(),
|
||||||
Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
|
Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ import fr.free.nrw.commons.utils.UrlUtils
|
||||||
import fr.free.nrw.commons.utils.ViewUtil
|
import fr.free.nrw.commons.utils.ViewUtil
|
||||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||||
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
||||||
|
import fr.free.nrw.commons.utils.setUnderlinedText
|
||||||
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage.Revision
|
import fr.free.nrw.commons.wikidata.mwapi.MwQueryPage.Revision
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
|
@ -319,8 +320,7 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
|
||||||
_binding = FragmentMediaDetailBinding.inflate(inflater, container, false)
|
_binding = FragmentMediaDetailBinding.inflate(inflater, container, false)
|
||||||
val view: View = binding.root
|
val view: View = binding.root
|
||||||
|
|
||||||
|
binding.seeMore.setUnderlinedText(R.string.nominated_see_more)
|
||||||
UnderlineUtils.setUnderlinedText(binding.seeMore, R.string.nominated_see_more, requireContext())
|
|
||||||
|
|
||||||
if (isCategoryImage) {
|
if (isCategoryImage) {
|
||||||
binding.authorLinearLayout.visibility = View.VISIBLE
|
binding.authorLinearLayout.visibility = View.VISIBLE
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package fr.free.nrw.commons.utils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.style.UnderlineSpan;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public final class UnderlineUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method sets underlined string text to a TextView
|
|
||||||
*
|
|
||||||
* @param textView TextView associated with string resource
|
|
||||||
* @param stringResourceName string resource name
|
|
||||||
* @param context
|
|
||||||
*/
|
|
||||||
public static void setUnderlinedText(final TextView textView, final int stringResourceName, final Context context) {
|
|
||||||
final SpannableString content = new SpannableString(context.getString(stringResourceName));
|
|
||||||
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
|
|
||||||
textView.setText(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package fr.free.nrw.commons.utils
|
||||||
|
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.text.buildSpannedString
|
||||||
|
import androidx.core.text.underline
|
||||||
|
|
||||||
|
object UnderlineUtils {
|
||||||
|
// Convenience method for Java usages - remove when those classes are converted
|
||||||
|
@JvmStatic
|
||||||
|
fun setUnderlinedText(textView: TextView, stringResourceName: Int) {
|
||||||
|
textView.setUnderlinedText(stringResourceName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun TextView.setUnderlinedText(stringResourceName: Int) {
|
||||||
|
text = buildSpannedString {
|
||||||
|
underline { append(context.getString(stringResourceName)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue