Merge branch 'dev' into agp-update

pull/535/head
Alinson S. Xavier 6 years ago
commit ded57cd04a

@ -5,8 +5,10 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.1' classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'org.jacoco:org.jacoco.core:0.8.4' classpath 'org.jacoco:org.jacoco.core:0.8.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
classpath 'org.ajoberstar:grgit:1.5.0' classpath 'org.ajoberstar:grgit:1.5.0'

@ -17,52 +17,41 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.isoron.uhabits.activities.intro; package org.isoron.uhabits.activities.intro
import android.graphics.*; import android.graphics.*
import android.os.*; import android.os.*
import com.github.paolorotolo.appintro.*; import com.github.paolorotolo.appintro.*
import org.isoron.uhabits.R; import org.isoron.uhabits.R
/** /**
* Activity that introduces the app to the user, shown only after the app is * Activity that introduces the app to the user, shown only after the app is
* launched for the first time. * launched for the first time.
*/ */
public class IntroActivity extends AppIntro2 class IntroActivity : AppIntro2() {
{ override fun init(savedInstanceState: Bundle?) {
@Override showStatusBar(false)
public void init(Bundle savedInstanceState)
{
showStatusBar(false);
addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_1), addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_1),
getString(R.string.intro_description_1), R.drawable.intro_icon_1, getString(R.string.intro_description_1), R.drawable.intro_icon_1,
Color.parseColor("#194673"))); Color.parseColor("#194673")))
addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_2), addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_2),
getString(R.string.intro_description_2), R.drawable.intro_icon_2, getString(R.string.intro_description_2), R.drawable.intro_icon_2,
Color.parseColor("#ffa726"))); Color.parseColor("#ffa726")))
addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_4), addSlide(AppIntroFragment.newInstance(getString(R.string.intro_title_4),
getString(R.string.intro_description_4), R.drawable.intro_icon_4, getString(R.string.intro_description_4), R.drawable.intro_icon_4,
Color.parseColor("#9575cd"))); Color.parseColor("#9575cd")))
} }
@Override override fun onNextPressed() {}
public void onNextPressed()
{
}
@Override override fun onDonePressed() {
public void onDonePressed() finish()
{
finish();
} }
@Override override fun onSlideChanged() {}
public void onSlideChanged()
{
}
} }

@ -35,8 +35,10 @@ class EditSettingActivity : BaseActivity() {
.setCompletedAllowed(true) .setCompletedAllowed(true)
.build()) .build())
val args = SettingUtils.parseIntent(this.intent, habits)
val controller = EditSettingController(this) val controller = EditSettingController(this)
val rootView = EditSettingRootView(this, habits, controller) val rootView = EditSettingRootView(this, habits, controller, args)
val screen = BaseScreen(this) val screen = BaseScreen(this)
screen.setRootView(rootView) screen.setRootView(rootView)
setScreen(screen) setScreen(screen)

@ -34,7 +34,8 @@ import java.util.*
class EditSettingRootView( class EditSettingRootView(
context: Context, context: Context,
private val habitList: HabitList, private val habitList: HabitList,
private val controller: EditSettingController private val controller: EditSettingController,
args: SettingUtils.Arguments?
) : BaseRootView(context) { ) : BaseRootView(context) {
@BindView(R.id.toolbar) @BindView(R.id.toolbar)
@ -50,6 +51,11 @@ class EditSettingRootView(
addView(inflate(getContext(), R.layout.automation, null)) addView(inflate(getContext(), R.layout.automation, null))
ButterKnife.bind(this) ButterKnife.bind(this)
populateHabitSpinner() populateHabitSpinner()
args?.let {
habitSpinner.setSelection(habitList.indexOf(it.habit))
actionSpinner.setSelection(it.action)
}
} }
override fun getToolbar(): Toolbar { override fun getToolbar(): Toolbar {

@ -44,7 +44,7 @@ class FireSettingReceiver : BroadcastReceiver() {
.habitsApplicationComponent(app.component) .habitsApplicationComponent(app.component)
.build() .build()
allHabits = app.component.habitList allHabits = app.component.habitList
val args = parseIntent(intent) ?: return val args = SettingUtils.parseIntent(intent, allHabits) ?: return
val timestamp = DateUtils.getToday() val timestamp = DateUtils.getToday()
val controller = component.widgetController val controller = component.widgetController
@ -55,19 +55,9 @@ class FireSettingReceiver : BroadcastReceiver() {
} }
} }
private fun parseIntent(intent: Intent): Arguments? {
val bundle = intent.getBundleExtra(EXTRA_BUNDLE) ?: return null
val action = bundle.getInt("action")
if (action < 0 || action > 2) return null
val habit = allHabits.getById(bundle.getLong("habit")) ?: return null
return Arguments(action, habit)
}
@ReceiverScope @ReceiverScope
@Component(dependencies = arrayOf(HabitsApplicationComponent::class)) @Component(dependencies = arrayOf(HabitsApplicationComponent::class))
internal interface ReceiverComponent { internal interface ReceiverComponent {
val widgetController: WidgetBehavior val widgetController: WidgetBehavior
} }
private class Arguments(var action: Int, var habit: Habit)
} }

@ -0,0 +1,18 @@
package org.isoron.uhabits.automation
import android.content.Intent
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.HabitList
object SettingUtils {
@JvmStatic
fun parseIntent(intent: Intent, allHabits: HabitList): Arguments? {
val bundle = intent.getBundleExtra(EXTRA_BUNDLE) ?: return null
val action = bundle.getInt("action")
if (action < 0 || action > 2) return null
val habit = allHabits.getById(bundle.getLong("habit")) ?: return null
return Arguments(action, habit)
}
class Arguments(var action: Int, var habit: Habit)
}

@ -84,11 +84,11 @@ class ListHabitsMenuTest : BaseAndroidJVMTest() {
verify(behavior).onViewAbout() verify(behavior).onViewAbout()
} }
@Test // @Test
fun testOnSelected_add() { // fun testOnSelected_add() {
onItemSelected(R.id.actionAdd) // onItemSelected(R.id.actionAdd)
verify(behavior).onCreateHabit() // verify(behavior).onCreateHabit()
} // }
@Test @Test
fun testOnSelected_faq() { fun testOnSelected_faq() {

@ -92,12 +92,12 @@ public class ListHabitsMenuBehaviorTest extends BaseUnitTest
assertFalse(matcherCaptor.getValue().isCompletedAllowed()); assertFalse(matcherCaptor.getValue().isCompletedAllowed());
} }
@Test // @Test
public void testOnCreateHabit() // public void testOnCreateHabit()
{ // {
behavior.onCreateHabit(); // behavior.onCreateHabit();
verify(screen).showCreateHabitScreen(); // verify(screen).showCreateHabitScreen();
} // }
@Test @Test
public void testOnSortByColor() public void testOnSortByColor()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

@ -59,7 +59,7 @@ class BarChart(var theme: Theme,
canvas.fillRect(0.0, 0.0, width, height) canvas.fillRect(0.0, 0.0, width, height)
fun barGroupOffset(c: Int) = marginLeft + paddingLeft + fun barGroupOffset(c: Int) = marginLeft + paddingLeft +
(nColumns - c - 1) * barGroupWidth (c) * barGroupWidth
fun barOffset(c: Int, s: Int) = barGroupOffset(c) + fun barOffset(c: Int, s: Int) = barGroupOffset(c) +
barGroupMargin + barGroupMargin +
@ -130,8 +130,8 @@ class BarChart(var theme: Theme,
val isLargeInterval = (axis[0].distanceTo(axis[1]) > 300) val isLargeInterval = (axis[0].distanceTo(axis[1]) > 300)
for (c in 0 until nColumns) { for (c in 0 until nColumns) {
val x = barGroupOffset(nColumns - c - 1) val x = barGroupOffset(c)
val date = axis[nColumns - c - 1] val date = axis[c]
if(isLargeInterval) { if(isLargeInterval) {
canvas.drawText(date.year.toString(), canvas.drawText(date.year.toString(),
x + barGroupWidth / 2, x + barGroupWidth / 2,

@ -0,0 +1,91 @@
# Build the project
This pages describes how to download and build the app from the source code. If you are having trouble building the project, please do not hesitate to open a new issue.
## Contents
* [Build using Android Studio](#build-using-android-studio)
* [Build from the command line](#build-from-the-command-line)
## Build using Android Studio
**Step 1: Install git**
The package `git` is required for downloading the source code of the app and submitting changes GitHub. Please see [the git book](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) for further instructions. If you are planning to submit pull requests in the future, it is recommended to [generate and configure your SSH keys](https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).
**Step 2: Download and install Android Studio**
Although Android Studio can be downloaded [from their official website](https://developer.android.com/studio/), a much better option is to install it through [JetBrains Toolbox](https://www.jetbrains.com/toolbox-app/). This tool, developed by the same developers of Android Studio, allows you to easily upgrade and downgrade the IDE, or switch between stable, beta and canary versions. After downloading and installing JetBrains Toolbox, simply click the install button near Android Studio to install the newest stable version of IDE. Beta and canary versions have not been tested and may not work correctly.
After installation, launch Android Studio. If this is the first time you launch it, you will need to go through a wizard to setup the IDE. The default options should work fine. The wizard will download all additional components necessary for development, including the emulator, so it may take a while.
**Step 3: Download the source code**
To create a complete copy of the source code repository, open the terminal (Linux/macOS) or Git Bash (Windows), navigate to the desired folder, then run:
```bash
git clone https://github.com/iSoron/uhabits.git
```
The repository will be downloaded to the directory `uhabits`. The Android files are located at `uhabits/android`.
**Step 4: Open and run the project on Android Studio**
1. Launch Android Studio and select "Open an existing Android Studio project".
2. When the IDE asks you for the project location, select `uhabits/android` and click "Ok".
3. Android Studio will spend some time indexing the project. When this is complete, click the toolbar icon "Sync Project with Gradle File", located near the right corner of the top toolbar.
4. The operation will likely fail several times due to missing Android SDK components. Each time it fails, click the link "Install missing platforms", "Instal build tools", etc, and try again.
5. To test the application, create a virtual Android device using the menu "Tools" and "AVD Manager". The default options should work fine, but free to customize the device.
6. Click the menu "Run" and "uhabits-android". The application should launch.
## Build from the command line
The following instructions were tested on **Ubuntu Linux 18.04 LTS** and may need to be modified for other operating systems.
**Step 1: Install basic packages**
To build the application, some basic packages are required. The package `git` is required to download the source code, while `openjdk-8-jdk-headless` is required for compiling Java and Kotlin files.
```bash
sudo apt-get update
sudo apt-get install -y git openjdk-8-jdk-headless
```
**IMPORTANT:** Newer JDK versions have not been tested and may not work correctly.
**Step 2: Install Android SDK tools**
The Android SDK tools contains many necessary tools for developing and debugging Android applications. It can be obtained as part of Android Studio, but, for simple command line usage, it can also be downloaded individually.
1. Download the file `sdk-tools-linux-4333796.zip` (or a newer version) from https://developer.android.com/studio/#downloads, and extract it somewhere. In this guide, we assume that it was extracted to `/opt/android-sdk/tools`; that is, the script `/opt/android-sdk/tools/bin/sdkmanager` should exist.
2. Append the following lines to `~/.profile`, so that other tools can locate your Android SDK installation. It is necessary to restart your terminal for these changes to take effect.
```
export PATH="$PATH:/opt/android-sdk/tools/bin"
export PATH="$PATH:/opt/android-sdk/platform-tools"
export ANDROID_HOME="/opt/android-sdk"
```
3. Accept all Android SDK licenses, by running
```bash
yes | sdkmanager --licenses
```
**Step 3: Download the source code**
To create a complete copy of the source code repository, navigate to your home directory and run:
```bash
git clone https://github.com/iSoron/uhabits.git
```
The repository will be downloaded to the directory `uhabits`.
**Step 4: Compile the source code**
1. Navigate to the directory `uhabits/android`
2. Run `./gradlew assembleDebug --stacktrace`
If the compilation is successful, a debug APK will be generated somewhere inside the folder `uhabits/android/uhabits-android/build/`. Currently, the full path is the following, but it may change in the future:
./uhabits/android/uhabits-android/build/outputs/apk/debug/uhabits-android-debug.apk
The APK can be installed using the tool `adb`, which should have been automatically installed at `/opt/android-sdk/platform-tools/adb` during compilation of the project.
Loading…
Cancel
Save