Start implementation of SyncActivity

feature/sync2
Alinson S. Xavier 4 years ago
parent 774412492f
commit 85b52a9840
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -79,6 +79,14 @@
android:value=".activities.habits.list.ListHabitsActivity" />
</activity>
<activity
android:name=".activities.sync.SyncActivity"
android:label="@string/device_sync">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.sync.SyncActivity" />
</activity>
<activity
android:name=".activities.intro.IntroActivity"
android:label=""

@ -0,0 +1,100 @@
/*
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker 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.
*
* Loop Habit Tracker 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/>.
*/
package org.isoron.uhabits.activities.sync
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.databinding.SyncActivityBinding
import org.isoron.uhabits.utils.setupToolbar
class SyncActivity : AppCompatActivity() {
private lateinit var binding: SyncActivityBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val component = (application as HabitsApplication).component
val themeSwitcher = AndroidThemeSwitcher(this, component.preferences)
themeSwitcher.apply()
binding = SyncActivityBinding.inflate(LayoutInflater.from(this))
binding.root.setupToolbar(
toolbar = binding.toolbar,
title = resources.getString(R.string.device_sync),
color = PaletteColor(11),
theme = themeSwitcher.currentTheme,
)
binding.generateButton.setOnClickListener { onGenerateCode() }
binding.enterButton.setOnClickListener {
val et = EditText(this)
AlertDialog.Builder(this)
.setTitle(R.string.sync_code)
.setView(et)
.setPositiveButton(R.string.save) { _, _ ->
onEnterCode(et.text.toString())
}
.show()
}
binding.disableButton.setOnClickListener {
AlertDialog.Builder(this)
.setTitle(R.string.disable_sync)
.setMessage(R.string.disable_sync_description)
.setPositiveButton(R.string.disable) { _, _ ->
onDisableSync()
}
.setNegativeButton(R.string.keep_enabled) { dialog, _ ->
dialog.dismiss()
}
.show()
}
setContentView(binding.root)
}
private fun onGenerateCode() {
showCodeScreen()
}
private fun onEnterCode(code: String) {
showCodeScreen()
}
private fun onDisableSync() {
showIntroScreen()
}
private fun showCodeScreen() {
binding.introGroup.visibility = View.GONE
binding.codeGroup.visibility = View.VISIBLE
}
private fun showIntroScreen() {
binding.introGroup.visibility = View.VISIBLE
binding.codeGroup.visibility = View.GONE
}
}

@ -0,0 +1,55 @@
<!--
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker 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.
~
~ Loop Habit Tracker 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/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="243dp"
android:height="85dp"
android:viewportWidth="243"
android:viewportHeight="85">
<path
android:pathData="M44.354,0H7.827C3.506,0 0,3.569 0,7.969V77.031C0,81.431 3.506,85 7.827,85H44.354C48.676,85 52.182,81.431 52.182,77.031V7.969C52.182,3.569 48.676,0 44.354,0ZM26.091,79.688C23.205,79.688 20.873,77.313 20.873,74.375C20.873,71.437 23.205,69.063 26.091,69.063C28.977,69.063 31.309,71.437 31.309,74.375C31.309,77.313 28.977,79.688 26.091,79.688ZM44.354,61.758C44.354,62.854 43.474,63.75 42.398,63.75H9.784C8.708,63.75 7.827,62.854 7.827,61.758V9.961C7.827,8.865 8.708,7.969 9.784,7.969H42.398C43.474,7.969 44.354,8.865 44.354,9.961V61.758Z"
android:fillColor="#ffffff" />
<path
android:pathData="M234.536,0H198.009C193.688,0 190.182,3.569 190.182,7.969V77.031C190.182,81.431 193.688,85 198.009,85H234.536C238.858,85 242.364,81.431 242.364,77.031V7.969C242.364,3.569 238.858,0 234.536,0ZM216.273,79.688C213.386,79.688 211.055,77.313 211.055,74.375C211.055,71.437 213.386,69.063 216.273,69.063C219.159,69.063 221.491,71.437 221.491,74.375C221.491,77.313 219.159,79.688 216.273,79.688ZM234.536,61.758C234.536,62.854 233.656,63.75 232.58,63.75H199.966C198.89,63.75 198.009,62.854 198.009,61.758V9.961C198.009,8.865 198.89,7.969 199.966,7.969H232.58C233.656,7.969 234.536,8.865 234.536,9.961V61.758Z"
android:fillColor="#ffffff" />
<path
android:pathData="M68.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M110.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M96.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M82.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M124.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M166.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M152.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
<path
android:pathData="M138.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#ffffff" />
</vector>

@ -0,0 +1,36 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="243dp"
android:height="85dp"
android:viewportWidth="243"
android:viewportHeight="85">
<path
android:pathData="M44.354,0H7.827C3.506,0 0,3.569 0,7.969V77.031C0,81.431 3.506,85 7.827,85H44.354C48.676,85 52.182,81.431 52.182,77.031V7.969C52.182,3.569 48.676,0 44.354,0ZM26.091,79.688C23.205,79.688 20.873,77.313 20.873,74.375C20.873,71.437 23.205,69.063 26.091,69.063C28.977,69.063 31.309,71.437 31.309,74.375C31.309,77.313 28.977,79.688 26.091,79.688ZM44.354,61.758C44.354,62.854 43.474,63.75 42.398,63.75H9.784C8.708,63.75 7.827,62.854 7.827,61.758V9.961C7.827,8.865 8.708,7.969 9.784,7.969H42.398C43.474,7.969 44.354,8.865 44.354,9.961V61.758Z"
android:fillColor="#000000" />
<path
android:pathData="M234.536,0H198.009C193.688,0 190.182,3.569 190.182,7.969V77.031C190.182,81.431 193.688,85 198.009,85H234.536C238.858,85 242.364,81.431 242.364,77.031V7.969C242.364,3.569 238.858,0 234.536,0ZM216.273,79.688C213.386,79.688 211.055,77.313 211.055,74.375C211.055,71.437 213.386,69.063 216.273,69.063C219.159,69.063 221.491,71.437 221.491,74.375C221.491,77.313 219.159,79.688 216.273,79.688ZM234.536,61.758C234.536,62.854 233.656,63.75 232.58,63.75H199.966C198.89,63.75 198.009,62.854 198.009,61.758V9.961C198.009,8.865 198.89,7.969 199.966,7.969H232.58C233.656,7.969 234.536,8.865 234.536,9.961V61.758Z"
android:fillColor="#000000" />
<path
android:pathData="M68.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M110.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M96.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M82.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M124.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M166.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M152.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
<path
android:pathData="M138.182,42.5a4,4.048 0,1 0,8 0a4,4.048 0,1 0,-8 0z"
android:fillColor="#000000" />
</vector>

@ -0,0 +1,162 @@
<!--
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
~
~ This file is part of Loop Habit Tracker.
~
~ Loop Habit Tracker 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.
~
~ Loop Habit Tracker 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/>.
-->
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/contrast0"
android:gravity="top|center">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
app:popupTheme="?toolbarPopupTheme"
style="@style/Toolbar" />
<ScrollView
android:id="@+id/introGroup"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="top|center">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="?attr/iconSync"
android:layout_margin="32dp"
android:alpha="0.25" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device_sync_description_1"
android:layout_marginBottom="16dp"
android:layout_marginTop="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device_sync_description_2"
android:layout_marginBottom="16dp"
android:layout_marginTop="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/generate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/generate_new_code"
app:backgroundTint="?attr/aboutScreenColor"
android:textColor="?attr/contrast0"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/enter_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enter_existing_code"
android:textColor="?attr/aboutScreenColor"
app:rippleColor="?attr/aboutScreenColor"
app:strokeColor="?attr/aboutScreenColor"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
</androidx.appcompat.widget.LinearLayoutCompat>
</ScrollView>
<ScrollView
android:id="@+id/codeGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sync_is_enabled"
android:layout_margin="16dp" />
<FrameLayout
style="@style/FormOuterBox"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="@string/sync_code" />
<TextView
style="@style/FormInput"
android:id="@+id/sync_code_tv"
android:fontFamily="monospace"
android:text="gravity trophy suspect shrimp sheriff avocado label trust tragic dove pitch title network myself task spell protect smooth diary sword brain blossom bulb under" />
</LinearLayout>
</FrameLayout>
<FrameLayout
style="@style/FormOuterBox"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="@string/last_sync" />
<TextView
style="@style/FormInput"
android:id="@+id/last_sync_tv"
android:text="Jan 10, 2022 4:45:00 PM" />
</LinearLayout>
</FrameLayout>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/disable_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/disable_sync"
android:textColor="?attr/aboutScreenColor"
app:rippleColor="?attr/aboutScreenColor"
app:strokeColor="?attr/aboutScreenColor"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
</LinearLayout>
</ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>

@ -43,6 +43,7 @@
<attr name="iconFilter" format="reference"/>
<attr name="iconArrowUp" format="reference"/>
<attr name="iconArrowDown" format="reference"/>
<attr name="iconSync" format="reference"/>
<attr name="dialogFormLabelColor" format="reference"/>
<attr name="toolbarPopupTheme" format="reference"/>

@ -232,4 +232,18 @@
<string name="activity_not_found">No app was found to support this action</string>
<string name="pref_midnight_delay_title">Extend day a few hours past midnight</string>
<string name="pref_midnight_delay_description">Wait until 3:00 AM to show a new day. Useful if you typically go to sleep after midnight. Requires app restart.</string>
<string name="device_sync">Device sync</string>
<string name="config_sync">Configure device sync</string>
<string name="config_sync_summary">Synchronize data across multiple devices. When enabled, an end-to-end encrypted copy of your data will be uploaded to Loop Habit Tracker servers.</string>
<string name="device_sync_description_1">Device sync allows you to keep your data synchronized across multiple devices. To get started, generate a new sync code below, install Loop Habit Tracker in another device, then type the generated code there.</string>
<string name="device_sync_description_2">When sync is enabled, an end-to-end encrypted copy of your data will be uploaded to Loop Habit Tracker servers. See privacy policy for more details.</string>
<string name="generate_new_code">Generate new code</string>
<string name="enter_existing_code">Enter existing code</string>
<string name="sync_is_enabled">Device sync is enabled. To get started, install Loop in another device, then type the following code there.</string>
<string name="sync_code">Sync code</string>
<string name="disable_sync">Disable sync</string>
<string name="disable_sync_description">Are you sure you want to disable sync on this device? This will not delete any data from any of your devices, but the current device will no longer be kept in sync with the others. If you disable sync from all devices, your data will be deleted from our servers in 30 days.</string>
<string name="disable">Disable</string>
<string name="keep_enabled">Keep enabled</string>
<string name="last_sync">Last sync</string>
</resources>

@ -45,6 +45,7 @@
<item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item>
<item name="iconArrowUp">@drawable/ic_arrow_up_light</item>
<item name="iconArrowDown">@drawable/ic_arrow_down_light</item>
<item name="iconSync">@drawable/ic_sync_light</item>
<item name="contrast0">@color/white</item>
<item name="contrast20">@color/grey_300</item>
<item name="contrast40">@color/grey_350</item>
@ -89,6 +90,7 @@
<item name="iconUnarchive">@drawable/ic_action_unarchive_dark</item>
<item name="iconArrowUp">@drawable/ic_arrow_up_dark</item>
<item name="iconArrowDown">@drawable/ic_arrow_down_dark</item>
<item name="iconSync">@drawable/ic_sync_dark</item>
<item name="contrast0">@color/grey_900</item>
<item name="contrast20">@color/grey_800</item>
<item name="contrast40">@color/grey_750</item>

@ -114,6 +114,24 @@
</PreferenceCategory>
<PreferenceCategory
android:key="syncCategory"
android:title="@string/device_sync">
<Preference
android:key="configSync"
android:summary="@string/config_sync_summary"
android:title="@string/config_sync"
app:iconSpaceReserved="false">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="org.isoron.uhabits.activities.sync.SyncActivity"
android:targetPackage="org.isoron.uhabits" />
</Preference>
</PreferenceCategory>
<PreferenceCategory
android:key="databaseCategory"
android:title="@string/database">

Loading…
Cancel
Save