-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adfda9e
commit cee39f4
Showing
22 changed files
with
348 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/fossasia/badgemagic/bindings/SettingsViewBindings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.fossasia.badgemagic.bindings | ||
|
||
import android.view.View | ||
import android.widget.AdapterView | ||
import android.widget.ArrayAdapter | ||
import androidx.appcompat.widget.AppCompatSpinner | ||
import androidx.databinding.BindingAdapter | ||
import org.fossasia.badgemagic.viewmodels.SettingsViewModel | ||
|
||
@BindingAdapter("createAdapterFrom") | ||
fun setSpinnerAdapter(spinner: AppCompatSpinner, viewModel: SettingsViewModel) { | ||
val list: MutableList<String> = viewModel.languageList.get() ?: mutableListOf() | ||
spinner.adapter = ArrayAdapter<String>(spinner.context, android.R.layout.simple_spinner_dropdown_item, list) | ||
spinner.setSelection(viewModel.getSelectedSpinnerLanguage(), false) | ||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { | ||
override fun onNothingSelected(parent: AdapterView<*>?) { | ||
} | ||
|
||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | ||
viewModel.setSelectedSpinnerLangauge(position) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.fossasia.badgemagic.data | ||
|
||
import java.util.Locale | ||
|
||
enum class Language(val locale: Locale) { | ||
ENGLISH(Locale.ENGLISH), | ||
CHINESE(Locale.CHINA), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/fossasia/badgemagic/ui/base/BaseActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.fossasia.badgemagic.ui.base | ||
|
||
import android.content.Context | ||
import androidx.appcompat.app.AppCompatActivity | ||
import org.fossasia.badgemagic.util.LocaleManager | ||
|
||
abstract class BaseActivity : AppCompatActivity() { | ||
override fun attachBaseContext(base: Context?) { | ||
super.attachBaseContext(LocaleManager.setLocale(base)) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...gemagic/ui/fragments/base/BaseFragment.kt → ...ssasia/badgemagic/ui/base/BaseFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 21 additions & 96 deletions
117
app/src/main/java/org/fossasia/badgemagic/ui/fragments/SettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,46 @@ | ||
package org.fossasia.badgemagic.ui.fragments | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.databinding.DataBindingUtil | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.lifecycle.Observer | ||
import com.google.android.material.snackbar.Snackbar | ||
import org.fossasia.badgemagic.R | ||
import org.fossasia.badgemagic.ui.fragments.base.BaseFragment | ||
import de.psdev.licensesdialog.LicensesDialog | ||
import de.psdev.licensesdialog.licenses.ApacheSoftwareLicense20 | ||
import de.psdev.licensesdialog.licenses.MITLicense | ||
import de.psdev.licensesdialog.model.Notice | ||
import de.psdev.licensesdialog.model.Notices | ||
import kotlinx.android.synthetic.main.fragment_about_us.* | ||
import org.fossasia.badgemagic.databinding.FragmentSettingsBinding | ||
import org.fossasia.badgemagic.ui.base.BaseFragment | ||
import org.fossasia.badgemagic.viewmodels.SettingsViewModel | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
|
||
class SettingsFragment : BaseFragment() { | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance() = | ||
SettingsFragment() | ||
SettingsFragment() | ||
} | ||
|
||
private val viewModel by viewModel<SettingsViewModel>() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.fragment_about_us, container, false) | ||
val binding = DataBindingUtil.inflate<FragmentSettingsBinding>(inflater, R.layout.fragment_settings, container, false) | ||
binding.viewModel = viewModel | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
about_fossasia.setOnClickListener { | ||
contributorsLink() | ||
} | ||
|
||
githubLayout.setOnClickListener { | ||
github() | ||
} | ||
|
||
ll_about_license.setOnClickListener { | ||
license() | ||
} | ||
|
||
ll_about_libs.setOnClickListener { | ||
libraryLicenseDialog() | ||
} | ||
} | ||
|
||
private fun contributorsLink() { | ||
val url = "https://github.com/fossasia/badge-magic-android/graphs/contributors" | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
intent.data = Uri.parse(url) | ||
startActivity(intent) | ||
} | ||
|
||
private fun github() { | ||
val url = "https://github.com/fossasia/badge-magic-android" | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
intent.data = Uri.parse(url) | ||
startActivity(intent) | ||
} | ||
|
||
private fun license() { | ||
val url = "https://github.com/fossasia/badge-magic-android/blob/development/LICENSE" | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
intent.data = Uri.parse(url) | ||
startActivity(intent) | ||
} | ||
|
||
private fun libraryLicenseDialog() { | ||
val notices = Notices() | ||
|
||
notices.addNotice( | ||
Notice( | ||
context?.getString(R.string.moshi), | ||
context?.getString(R.string.moshi_github), | ||
context?.getString(R.string.moshi_copy), | ||
ApacheSoftwareLicense20() | ||
) | ||
) | ||
notices.addNotice( | ||
Notice( | ||
context?.getString(R.string.gif), | ||
context?.getString(R.string.gif_github), | ||
context?.getString(R.string.gif_copy), | ||
ApacheSoftwareLicense20() | ||
) | ||
) | ||
notices.addNotice( | ||
Notice( | ||
context?.getString(R.string.timber), | ||
context?.getString(R.string.timber_github), | ||
context?.getString(R.string.timber_copy), | ||
MITLicense() | ||
) | ||
) | ||
notices.addNotice( | ||
Notice( | ||
context?.getString(R.string.scanner), | ||
context?.getString(R.string.scanner_github), | ||
context?.getString(R.string.scanner_copy), | ||
ApacheSoftwareLicense20() | ||
) | ||
) | ||
notices.addNotice( | ||
Notice( | ||
context?.getString(R.string.licences), | ||
context?.getString(R.string.licences_github), | ||
context?.getString(R.string.licences_copy), | ||
ApacheSoftwareLicense20() | ||
) | ||
) | ||
viewModel.changedLanguage.observe(viewLifecycleOwner, Observer { | ||
|
||
LicensesDialog.Builder(context) | ||
.setNotices(notices) | ||
.setIncludeOwnLicense(true) | ||
.build() | ||
Snackbar | ||
.make(view, requireContext().getString(R.string.change_language), Snackbar.LENGTH_INDEFINITE) | ||
.setAction("RESTART") { | ||
requireActivity().finishAffinity() | ||
startActivity(requireActivity().intent) | ||
} | ||
.show() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.