Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Nov 22, 2016
2 parents a5404b0 + b3e32c1 commit 427592e
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 29 deletions.
15 changes: 6 additions & 9 deletions README.md
@@ -1,4 +1,6 @@
# Cicerone
[![Bintray](https://img.shields.io/bintray/v/terrakok/terramaven/cicerone.svg)](https://bintray.com/terrakok/terramaven/cicerone)
[![License](https://img.shields.io/badge/license-APACHE2-blue.svg)](http://choosealicense.com/licenses/apache-2.0/)

Cicerone (a guide, one who conducts sightseers) is a lightweight library that makes the navigation in an Android app easy.
It was designed to be used with the MVP pattern (try [Moxy](https://github.com/Arello-Mobile/Moxy)), but will work great with any architecture.
Expand All @@ -12,20 +14,15 @@ It was designed to be used with the MVP pattern (try [Moxy](https://github.com/A
+ suitable for Unit Testing

## How to add
Add the following lines to your build.gradle:
Add the dependency in your build.gradle:
```groovy
repositories {
maven {
url 'https://dl.bintray.com/terrakok/terramaven/'
}
}
dependencies {
//Cicerone
compile 'ru.terrakok.cicerone:cicerone:1.0'
compile 'ru.terrakok.cicerone:cicerone:1.1'
}
```
Initialize the library (usually in your Application class):

Initialize the library (for example in your Application class):
```java
public class SampleApplication extends MvpApplication {
public static SampleApplication INSTANCE;
Expand Down
10 changes: 2 additions & 8 deletions README_RUS.md
Expand Up @@ -12,17 +12,11 @@ Cicerone (_"чи-че-ро́-не"_ - устар. гид) - легкая биб
+ приспособлена для Unit тестов

## Как подключить?
Добавьте в build.gradle следующие строки:
Добавьте в build.gradle зависимость:
```groovy
repositories {
maven {
url 'https://dl.bintray.com/terrakok/terramaven/'
}
}
dependencies {
//Cicerone
compile 'ru.terrakok.cicerone:cicerone:1.0'
compile 'ru.terrakok.cicerone:cicerone:1.1'
}
```
И инициализируйте библиотеку, например, так:
Expand Down
5 changes: 2 additions & 3 deletions library/build.gradle
Expand Up @@ -6,8 +6,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
compileOnly 'com.google.android:android:4.0.1.2'
compileOnly project(':stub-appcompat')
compileOnly project(':stub-android')
}

ext {
Expand All @@ -16,7 +15,7 @@ ext {
bintrayName = 'cicerone'
publishedGroupId = 'ru.terrakok.cicerone'
artifact = 'cicerone'
libraryVersion = '1.0'
libraryVersion = '1.1'
gitUrl = 'https://github.com/terrakok/Cicerone'
allLicenses = ['Apache-2.0']
}
Expand Down
Expand Up @@ -2,7 +2,3 @@ apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
compileOnly 'com.google.android:android:4.0.1.2'
}
7 changes: 7 additions & 0 deletions library/stub-android/src/main/java/android/app/Activity.java
@@ -0,0 +1,7 @@
package android.app;

/***
* Created by laomo on 2016-11-21.
*/
public class Activity {
}
36 changes: 36 additions & 0 deletions library/stub-android/src/main/java/android/app/Fragment.java
@@ -0,0 +1,36 @@
package android.app;

import android.os.Bundle;

/***
* Created by laomo on 2016-11-21.
*/
public class Fragment {
public void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}

public void onStart() {
throw new RuntimeException("Stub!");
}

public void onDestroyView() {
throw new RuntimeException("Stub!");
}

public void onDestroy() {
throw new RuntimeException("Stub!");
}

public void onSaveInstanceState(Bundle outState) {
throw new RuntimeException("Stub!");
}

final public boolean isRemoving() {
throw new RuntimeException("Stub!");
}

public final Activity getActivity() {
throw new RuntimeException("Stub!");
}
}
@@ -0,0 +1,41 @@
package android.app;

/***
* Created by laomo on 2016-11-21.
*/
public class FragmentManager {

public FragmentTransaction beginTransaction() {
throw new RuntimeException("Stub!");
}

public boolean executePendingTransactions() {
throw new RuntimeException("Stub!");
}

public void popBackStack() {
throw new RuntimeException("Stub!");
}

public boolean popBackStackImmediate() {
throw new RuntimeException("Stub!");
}

public boolean popBackStackImmediate(String name, int flags) {
throw new RuntimeException("Stub!");
}

public int getBackStackEntryCount() {
throw new RuntimeException("Stub!");
}

public BackStackEntry getBackStackEntryAt(int index) {
throw new RuntimeException("Stub!");
}

public interface BackStackEntry {
int getId();

String getName();
}
}
@@ -0,0 +1,18 @@
package android.app;

/***
* Created by laomo on 2016-11-21.
*/
public class FragmentTransaction {
public FragmentTransaction replace(int containerViewId, Fragment fragment) {
throw new RuntimeException("Stub!");
}

public FragmentTransaction addToBackStack(String name) {
throw new RuntimeException("Stub!");
}

public int commit() {
throw new RuntimeException("Stub!");
}
}
7 changes: 7 additions & 0 deletions library/stub-android/src/main/java/android/os/Bundle.java
@@ -0,0 +1,7 @@
package android.os;

/***
* Created by laomo on 2016-11-21.
*/
public class Bundle {
}
8 changes: 5 additions & 3 deletions sample/src/main/AndroidManifest.xml
Expand Up @@ -7,15 +7,17 @@
android:name=".SampleApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:label="@string/app_name">
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name=".ui.main.MainActivity">
android:name=".ui.start.StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity android:name=".ui.main.MainActivity"/>
</application>
</manifest>
2 changes: 2 additions & 0 deletions sample/src/main/java/ru/terrakok/cicerone/sample/Screens.java
Expand Up @@ -7,4 +7,6 @@

public class Screens {
public static final String SAMPLE_SCREEN = "sample_screen_";
public static final String START_ACTIVITY_SCREEN = "start activity screen";
public static final String MAIN_ACTIVITY_SCREEN = "main activity screen";
}
@@ -0,0 +1,26 @@
package ru.terrakok.cicerone.sample.mvp.start;

import com.arellomobile.mvp.MvpPresenter;

import ru.terrakok.cicerone.Router;
import ru.terrakok.cicerone.sample.SampleApplication;
import ru.terrakok.cicerone.sample.Screens;

/**
* Created by terrakok 21.11.16
*/
public class StartActivityPresenter extends MvpPresenter<StartActivityView> {
private Router router;

public StartActivityPresenter() {
router = SampleApplication.INSTANCE.getRouter();
}

public void onNextPressed() {
router.replaceScreen(Screens.MAIN_ACTIVITY_SCREEN);
}

public void onBackPressed() {
router.exit();
}
}
@@ -0,0 +1,9 @@
package ru.terrakok.cicerone.sample.mvp.start;

import com.arellomobile.mvp.MvpView;

/**
* Created by terrakok 21.11.16
*/
public interface StartActivityView extends MvpView {
}
@@ -0,0 +1,113 @@
package ru.terrakok.cicerone.sample.ui.start;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.arellomobile.mvp.MvpAppCompatActivity;
import com.arellomobile.mvp.presenter.InjectPresenter;

import ru.terrakok.cicerone.Navigator;
import ru.terrakok.cicerone.commands.Back;
import ru.terrakok.cicerone.commands.Command;
import ru.terrakok.cicerone.commands.Forward;
import ru.terrakok.cicerone.commands.Replace;
import ru.terrakok.cicerone.commands.SystemMessage;
import ru.terrakok.cicerone.sample.R;
import ru.terrakok.cicerone.sample.SampleApplication;
import ru.terrakok.cicerone.sample.Screens;
import ru.terrakok.cicerone.sample.mvp.start.StartActivityPresenter;
import ru.terrakok.cicerone.sample.mvp.start.StartActivityView;
import ru.terrakok.cicerone.sample.ui.main.MainActivity;

/**
* Created by terrakok 21.11.16
*/
public class StartActivity extends MvpAppCompatActivity implements StartActivityView {
@InjectPresenter
StartActivityPresenter presenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_start);
initViews();
}

private void initViews() {
findViewById(R.id.lets_go_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
presenter.onNextPressed();
}
});
}

@Override
protected void onResume() {
super.onResume();
SampleApplication.INSTANCE.getNavigatorHolder().setNavigator(navigator);
}

@Override
protected void onPause() {
SampleApplication.INSTANCE.getNavigatorHolder().removeNavigator();
super.onPause();
}

@Override
public void onBackPressed() {
presenter.onBackPressed();
}

private Navigator navigator = new Navigator() {
@Override
public void applyCommand(Command command) {
if (command instanceof Forward) {
forward((Forward) command);
} else if (command instanceof Replace) {
replace((Replace) command);
} else if (command instanceof Back) {
back();
} else if (command instanceof SystemMessage) {
Toast.makeText(StartActivity.this, ((SystemMessage) command).getMessage(), Toast.LENGTH_SHORT).show();
} else {
Log.e("Cicerone", "Illegal command for this screen: " + command.getClass().getSimpleName());
}
}

private void forward(Forward command) {
switch (command.getScreenKey()) {
case Screens.START_ACTIVITY_SCREEN:
startActivity(new Intent(StartActivity.this, StartActivity.class));
break;
case Screens.MAIN_ACTIVITY_SCREEN:
startActivity(new Intent(StartActivity.this, MainActivity.class));
break;
default:
Log.e("Cicerone", "Unknown screen: " + command.getScreenKey());
break;
}
}

private void replace(Replace command) {
switch (command.getScreenKey()) {
case Screens.START_ACTIVITY_SCREEN:
case Screens.MAIN_ACTIVITY_SCREEN:
forward(new Forward(command.getScreenKey(), command.getTransitionData()));
finish();
break;
default:
Log.e("Cicerone", "Unknown screen: " + command.getScreenKey());
break;
}
}

private void back() {
finish();
}
};
}

0 comments on commit 427592e

Please sign in to comment.