AboutFragment.kt 5.28 KB
Newer Older
1
2
package com.frostnerd.smokescreen.fragment

Daniel Wolf's avatar
Daniel Wolf committed
3
import android.content.ActivityNotFoundException
4
5
6
7
8
9
10
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Daniel Wolf's avatar
Daniel Wolf committed
11
import android.widget.Toast
12
13
14
15
16
import androidx.fragment.app.Fragment
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.database.AppDatabase
import com.frostnerd.smokescreen.dialog.ChangelogDialog
import com.frostnerd.smokescreen.dialog.LicensesDialog
17
import com.frostnerd.smokescreen.dialog.QueryGeneratorDialog
18
import com.frostnerd.smokescreen.util.preferences.Crashreporting
19
import kotlinx.android.synthetic.main.fragment_about.view.*
20
import java.util.*
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

/*
 * Copyright (C) 2019 Daniel Wolf (Ch4t4r)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You can contact the developer at daniel.wolf@frostnerd.com.
 */
class AboutFragment : Fragment() {
Daniel Wolf's avatar
Daniel Wolf committed
41
    private var queryGenStepOne = false
42
43
44
45
46
47
48
49

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_about, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        view.credits.setOnClickListener {
            showInfoTextDialog(
50
                requireContext(),
51
                getString(R.string.dialog_credits_title),
Daniel Wolf's avatar
Daniel Wolf committed
52
53
                getString(R.string.dialog_credits_message),
                linkifyText = true
54
55
56
            )
        }
        view.privacyPolicy.setOnClickListener {
57
            showPrivacyPolicyDialog(requireContext())
58
        }
59
        if(isPackageInstalled(requireContext(), "org.telegram.messenger")) {
60
61
62
63
64
65
66
67
            view.group.setOnClickListener {
                val intent = Intent(Intent.ACTION_VIEW, Uri.parse("tg://join?invite=I54nRleveRGP8IPmcIdySg"))
                startActivity(intent)
            }
        } else {
            view.group.visibility = View.GONE
        }
        view.contact.setOnClickListener {
68
            requireContext().showEmailChooser(
69
70
71
                getString(R.string.about_contact_developer),
                getString(R.string.app_name),
                getString(R.string.support_contact_mail),
72
                "\n\n\n\n\n\nSystem:\nApp version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE};${BuildConfig.COMMIT_HASH})\n" +
73
74
75
76
77
78
79
80
81
82
83
                        "Android: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE} - ${Build.VERSION.CODENAME})"
            )
        }
        view.share.setOnClickListener {
            val intent = Intent(Intent.ACTION_SEND)
            intent.type = "text/plain"
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name))
            intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.app_share_text))
            startActivity(Intent.createChooser(intent, getString(R.string.about_share)))
        }
        view.changelog.setOnClickListener {
84
            ChangelogDialog(requireContext(), 22, showOptOut = false, showInfoText = false).show()
85
86
        }
        view.licenses.setOnClickListener {
87
            LicensesDialog(requireContext()).show()
88
89
90
        }
        view.about.setOnClickListener {
            showInfoTextDialog(
91
                requireContext(),
92
93
94
                getString(R.string.menu_about),
                getString(
                    R.string.about_app,
95
                    BuildConfig.VERSION_NAME + (if (BuildConfig.DEBUG) " DEBUG" else "") + " (Commit ${BuildConfig.COMMIT_HASH})",
96
97
                    BuildConfig.VERSION_CODE,
                    AppDatabase.currentVersion,
98
                    if (requireContext().getPreferences().crashreportingType == Crashreporting.FULL) requireContext().getPreferences().crashReportingUUID else "---"
Daniel Wolf's avatar
Daniel Wolf committed
99
100
                ),
                linkifyText = true
101
102
103
104
            )
        }
        val languageCode = Locale.getDefault().toString()
        if (!resources.getStringArray(R.array.missing_languages).any {
105
                languageCode.startsWith(it, true)
106
107
            }) view.translating.visibility = View.GONE
        else view.translating.setOnClickListener {
108
            showInfoTextDialog(requireContext(), getString(R.string.about_help_translating),
109
110
                getString(R.string.dialog_help_translating_message),
                neutralButton = getString(R.string.all_close) to null)
111
        }
112
113
114
115
116
117
118
119
        view.privacyPolicy.setOnLongClickListener {
            queryGenStepOne = true
            true
        }
        view.about.setOnLongClickListener {
            if(queryGenStepOne) QueryGeneratorDialog(requireContext())
            true
        }
Daniel Wolf's avatar
Daniel Wolf committed
120
        view.faq.setOnClickListener {
121
            requireContext().tryOpenBrowser("https://nebulo.app/faq")
Daniel Wolf's avatar
Daniel Wolf committed
122
        }
123
124
    }
}