1
1
package info.dvkr.screenstream.ui.fragment
2
2
3
- import android.content.ActivityNotFoundException
4
3
import android.content.Intent
5
4
import android.net.Uri
6
5
import android.os.Bundle
7
6
import android.view.View
8
7
import android.widget.Toast
9
8
import androidx.fragment.app.Fragment
10
- import com.afollestad.materialdialogs.MaterialDialog
11
- import com.afollestad.materialdialogs.lifecycle.lifecycleOwner
12
9
import com.elvishew.xlog.XLog
13
10
import info.dvkr.screenstream.R
14
11
import info.dvkr.screenstream.data.other.getLog
@@ -28,99 +25,48 @@ class AboutFragment : Fragment(R.layout.fragment_about) {
28
25
override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
29
26
super .onViewCreated(view, savedInstanceState)
30
27
31
- with (requireActivity()) {
32
- try {
33
- version = packageManager.getPackageInfo(packageName, 0 ).versionName
34
- binding.tvFragmentAboutVersion.text = getString(R .string.about_fragment_app_version, version)
35
- } catch (t: Throwable ) {
36
- XLog .e(getLog(" onViewCreated" , " getPackageInfo" ), t)
37
- }
28
+ val packageName = requireContext().packageName
38
29
39
- binding.tvFragmentAboutVersion.setOnClickListener {
40
- settingsLoggingVisibleCounter++
41
- if (settingsLoggingVisibleCounter >= 5 ) {
42
- settings.loggingVisible = true
43
- Toast .makeText(requireContext().applicationContext, " Logging option enabled" , Toast .LENGTH_LONG )
44
- .show()
45
- }
46
- }
30
+ runCatching {
31
+ version = requireContext().packageManager.getPackageInfo(packageName, 0 ).versionName
32
+ binding.tvFragmentAboutVersion.text = getString(R .string.about_fragment_app_version, version)
33
+ }.onFailure {
34
+ XLog .e(getLog(" onViewCreated" , " getPackageInfo" ), it)
35
+ }
47
36
48
- binding.bFragmentAboutRate.setOnClickListener {
49
- try {
50
- startActivity(
51
- Intent (
52
- Intent .ACTION_VIEW ,
53
- Uri .parse(" market://details?id=$packageName " )
54
- ).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
55
- )
56
- } catch (ignore: ActivityNotFoundException ) {
57
- startActivity(
58
- Intent (
59
- Intent .ACTION_VIEW ,
60
- Uri .parse(" https://play.google.com/store/apps/details?id=$packageName " )
61
- ).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
62
- )
63
- }
37
+ binding.tvFragmentAboutVersion.setOnClickListener {
38
+ settingsLoggingVisibleCounter++
39
+ if (settingsLoggingVisibleCounter >= 5 ) {
40
+ settings.loggingVisible = true
41
+ Toast .makeText(requireContext(), " Logging option enabled" , Toast .LENGTH_LONG ).show()
64
42
}
65
43
}
66
44
67
- binding.bFragmentAboutDeveloperEmail.setOnClickListener {
68
- MaterialDialog (requireActivity()).show {
69
- lifecycleOwner(viewLifecycleOwner)
70
- title(R .string.about_fragment_write_email_dialog)
71
- icon(R .drawable.ic_about_feedback_24dp)
72
- positiveButton(android.R .string.cancel)
73
- negativeButton(android.R .string.yes) {
74
- val emailIntent = Intent (Intent .ACTION_SENDTO )
75
- .addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
76
- .setData(Uri .Builder ().scheme(" mailto" ).build())
77
- .putExtra(Intent .EXTRA_EMAIL , arrayOf(" Dmitriy Krivoruchko <dkrivoruchko@gmail.com>" ))
78
- .putExtra(Intent .EXTRA_SUBJECT , " Screen Stream Feedback ($version )" )
79
- startActivity(
80
- Intent .createChooser(emailIntent, getString(R .string.about_fragment_email_chooser_header))
81
- )
82
- }
45
+ binding.bFragmentAboutRate.setOnClickListener {
46
+ openStringUrl(" market://details?id=$packageName " ) {
47
+ openStringUrl(" https://play.google.com/store/apps/details?id=$packageName " )
83
48
}
84
49
}
85
50
86
51
binding.bFragmentAboutSources.setOnClickListener {
87
- try {
88
- startActivity(
89
- Intent (
90
- Intent .ACTION_VIEW ,
91
- Uri .parse(" https://github.com/dkrivoruchko/ScreenStream" )
92
- ).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
93
- )
94
-
95
- } catch (ignore: ActivityNotFoundException ) {
96
- }
52
+ openStringUrl(" https://github.com/dkrivoruchko/ScreenStream" )
97
53
}
98
54
99
55
binding.bFragmentPrivacyPolicy.setOnClickListener {
100
- try {
101
- startActivity(
102
- Intent (
103
- Intent .ACTION_VIEW ,
104
- Uri .parse(" https://github.com/dkrivoruchko/ScreenStream/blob/master/PrivacyPolicy.md" )
105
- ).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
106
- )
107
-
108
- } catch (ignore: ActivityNotFoundException ) {
109
- }
56
+ openStringUrl(" https://github.com/dkrivoruchko/ScreenStream/blob/master/PrivacyPolicy.md" )
110
57
}
111
58
112
59
binding.bFragmentLicense.setOnClickListener {
113
- try {
114
- startActivity(
115
- Intent (
116
- Intent .ACTION_VIEW ,
117
- Uri .parse(" https://github.com/dkrivoruchko/ScreenStream/blob/master/LICENSE" )
118
- ).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
119
- )
120
-
121
- } catch (ignore: ActivityNotFoundException ) {
122
- }
60
+ openStringUrl(" https://github.com/dkrivoruchko/ScreenStream/blob/master/LICENSE" )
123
61
}
124
62
125
63
}
64
+
65
+ private fun openStringUrl (url : String , onFailure : () -> Unit = {}) {
66
+ runCatching {
67
+ startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(url)).addFlags(Intent .FLAG_ACTIVITY_NEW_TASK ))
68
+ }.onFailure {
69
+ runCatching { onFailure.invoke() }
70
+ }
71
+ }
126
72
}
0 commit comments