Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate code base to KTX #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"

compileSdkVersion 28
defaultConfig {
applicationId "me.yokeyword.swipebackfragment.sample"
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -20,8 +19,12 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile project(':swipeback')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation project(':swipeback')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.yokeyword.swipebackfragment.sample;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import androidx.appcompat.widget.Toolbar;
import android.view.View;

import androidx.fragment.app.Fragment;
import me.yokeyword.swipebackfragment.SwipeBackFragment;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.yokeyword.swipebackfragment.sample;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import me.yokeyword.swipebackfragment.SwipeBackActivity;
import me.yokeyword.swipebackfragment.sample.fragment.FirstSwipeBackFragment;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.yokeyword.swipebackfragment.sample;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -10,6 +9,8 @@
import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;


/**
* Created by YoKeyword on 16/4/21.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.yokeyword.swipebackfragment.sample.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package me.yokeyword.swipebackfragment.sample.fragment;

import androidx.appcompat.widget.Toolbar;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import me.yokeyword.swipebackfragment.sample.BaseSwipeBackFragment;
import me.yokeyword.swipebackfragment.sample.PagerAdapter;
import me.yokeyword.swipebackfragment.sample.R;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.yokeyword.swipebackfragment.sample.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.GravityCompat;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.yokeyword.swipebackfragment.sample.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.GravityCompat;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_swipe_back_recy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<include layout="@layout/toolbar"/>

<android.support.v7.widget.RecyclerView
<androidx.appcompat.widget.RecyclerView
android:id="@+id/recy"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/toolbar.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
Expand Down
15 changes: 13 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.10'
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'

classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -15,6 +21,11 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Wed Nov 28 14:35:40 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
19 changes: 12 additions & 7 deletions swipeback/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.jamesdeperio'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28

defaultConfig {
minSdkVersion 9
targetSdkVersion 22
minSdkVersion 16
targetSdkVersion 28

consumerProguardFiles 'proguard-rules.pro'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'com.android.support:appcompat-v7:25.2.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'androidx.appcompat:appcompat:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package me.yokeyword.swipebackfragment

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.annotation.DrawableRes
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import android.view.ViewGroup


/**
* SwipeBackActivity
* Created by YoKeyword on 16/4/19.
*/
open class SwipeBackActivity : AppCompatActivity() {
var swipeBackLayout: SwipeBackLayout? = null
/**
* 当Fragment根布局 没有 设定background属性时,
* 库默认使用Theme的android:windowbackground作为Fragment的背景,
* 如果不像使用windowbackground作为背景, 可以通过该方法改变Fragment背景。
*/
var defaultFragmentBackground = 0


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
onActivityCreate()
}

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
swipeBackLayout!!.attachToActivity(this)
}


private fun onActivityCreate() {
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
window.decorView.background=null
swipeBackLayout = SwipeBackLayout(this)
val params = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
swipeBackLayout!!.layoutParams = params
}

open fun setEdgeLevel(edgeLevel: SwipeBackLayout.EdgeLevel) {
swipeBackLayout!!.edgeLevel = edgeLevel
}

open fun setEdgeLevel(widthPixel: Int) {
swipeBackLayout!!.setEdgeLevel(widthPixel)
}

open fun setSwipeBackEnable(enable: Boolean) {
swipeBackLayout!!.setEnableGesture(enable)
}

/**
* 限制SwipeBack的条件,默认栈内Fragment数 <= 1时 , 优先滑动退出Activity , 而不是Fragment
*
* @return true: Activity可以滑动退出, 并且总是优先; false: Activity不允许滑动退出
*/
open fun swipeBackPriority(): Boolean = supportFragmentManager.backStackEntryCount <= 1
}
Loading