Skip to content

Commit

Permalink
Merge branch 'release/v5.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Nov 2, 2015
2 parents 3d7cae1 + 7b90438 commit cd13cc6
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 268 deletions.
11 changes: 11 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
###Upgrade Notes

#### v5.2.6 -> 5.3.0
* change `.fragment()` to `.supportFragment()` and `LibsFragment` to `LibsSupportFragment`

**INFO**
* moved logic of the fragment to the new `LibsFragmentCompat` class
* create new `LibsSupportFragment` which extends the `android.support.v4.app.Fragment`
* change the `LibsFragment` which now extends the `android.app.Fragment`
* add new method `.supportFragment()` which returns `android.support.v4.app.Fragment`
* change `.fragment()` which now returns `android.app.Fragment`
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Here's a quick overview of functions it include:

Most modern apps feature an "Used Library"-section and for this some information of those libs is required. As it gets annoying to copy those strings always to your app I've developed this small helper library to provide the required information.

#Migration
- [MIGRATION GUIDE](https://github.com/mikepenz/AboutLibraries/blob/develop/MIGRATION.md)

#Get started
- [Include in your project](#include-in-your-project)
- [Usage](#usage)
Expand Down Expand Up @@ -46,7 +49,7 @@ You can find anything you search for in the wiki. (If not open an issue)
The AboutLibraries Library is pushed to [Maven Central](http://search.maven.org/#search|ga|1|g%3A%22com.mikepenz%22), so you just need to add the following dependency to your `build.gradle`. It seems it is also required to add the support dependencies to the application. If it works without, you should be fine too :).

```javascript
compile('com.mikepenz:aboutlibraries:5.2.7@aar') {
compile('com.mikepenz:aboutlibraries:5.3.0@aar') {
transitive = true
}
```
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=5.2.7
VERSION_CODE=527
VERSION_NAME=5.3.0
VERSION_CODE=530
GROUP=com.mikepenz

POM_DESCRIPTION=AboutLibraries Library
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 527
versionName '5.2.7'
versionCode 530
versionName '5.3.0'
}

buildTypes {
Expand Down
18 changes: 18 additions & 0 deletions library/src/main/java/com/mikepenz/aboutlibraries/LibsBuilder.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.mikepenz.aboutlibraries;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.LayoutAnimationController;

import com.mikepenz.aboutlibraries.entity.Library;
import com.mikepenz.aboutlibraries.ui.LibsActivity;
import com.mikepenz.aboutlibraries.ui.LibsFragment;
import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
import com.mikepenz.aboutlibraries.ui.adapter.LibsRecyclerViewAdapter;
import com.mikepenz.aboutlibraries.util.Colors;

Expand Down Expand Up @@ -507,12 +510,27 @@ public void activity(Context ctx) {
*
* @return the fragment to set in your application
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public LibsFragment fragment() {
Bundle bundle = new Bundle();
bundle.putSerializable("data", this);

LibsFragment fragment = new LibsFragment();
fragment.setArguments(bundle);
return fragment;
}

/**
* supportFragment() method to build and create the fragment with the set params
*
* @return the fragment to set in your application
*/
public LibsSupportFragment supportFragment() {
Bundle bundle = new Bundle();
bundle.putSerializable("data", this);

LibsSupportFragment fragment = new LibsSupportFragment();
fragment.setArguments(bundle);

return fragment;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package com.mikepenz.aboutlibraries;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;

import com.mikepenz.aboutlibraries.entity.Library;
import com.mikepenz.aboutlibraries.ui.adapter.LibsRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
* Created by mikepenz on 02.11.15.
*/
public class LibsFragmentCompat {
private RecyclerView mRecyclerView;
private LibsRecyclerViewAdapter mAdapter;

private LibsBuilder builder = null;

private static ArrayList<Library> libraries;

private Comparator<Library> comparator;

private AsyncTask mLibTask;

/**
* Default Constructor
* Gets an libs instance and gets all external libs
*/
public LibsFragmentCompat() {
}

public void setLibraryComparator(final Comparator<Library> comparator) {
this.comparator = comparator;
}

public void onAttach(Context context, Bundle bundle) {
if (bundle != null) {
builder = (LibsBuilder) bundle.getSerializable("data");
} else {
Log.e("AboutLibraries", "The AboutLibraries fragment can't be build without the bundle containing the LibsBuilder");
return;
}
}

private class LibraryTask extends AsyncTask<String, String, String> {
Context ctx;

String versionName;
Integer versionCode;
Drawable icon = null;

public LibraryTask(Context ctx) {
this.ctx = ctx;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected String doInBackground(String... strings) {
//init the Libs instance with fields if they were set
Libs libs = null;
if (builder == null || builder.fields == null) {
libs = new Libs(ctx);
} else {
libs = new Libs(ctx, builder.fields);
}

//fill the builder with the information
builder.aboutShowIcon = extractBooleanBundleOrResource(ctx, libs, builder.aboutShowIcon, "aboutLibraries_description_showIcon");
builder.aboutShowVersion = extractBooleanBundleOrResource(ctx, libs, builder.aboutShowVersion, "aboutLibraries_description_showVersion");
builder.aboutShowVersionName = extractBooleanBundleOrResource(ctx, libs, builder.aboutShowVersionName, "aboutLibraries_description_showVersionName");
builder.aboutShowVersionCode = extractBooleanBundleOrResource(ctx, libs, builder.aboutShowVersionCode, "aboutLibraries_description_showVersionCode");

builder.aboutAppName = extractStringBundleOrResource(ctx, libs, builder.aboutAppName, "aboutLibraries_description_name");
builder.aboutDescription = extractStringBundleOrResource(ctx, libs, builder.aboutDescription, "aboutLibraries_description_text");

builder.aboutAppSpecial1 = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial1, "aboutLibraries_description_special1_name");
builder.aboutAppSpecial1Description = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial1Description, "aboutLibraries_description_special1_text");
builder.aboutAppSpecial2 = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial2, "aboutLibraries_description_special2_name");
builder.aboutAppSpecial2Description = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial2Description, "aboutLibraries_description_special2_text");
builder.aboutAppSpecial3 = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial3, "aboutLibraries_description_special3_name");
builder.aboutAppSpecial3Description = extractStringBundleOrResource(ctx, libs, builder.aboutAppSpecial3Description, "aboutLibraries_description_special3_text");

//only if the libs were not loaded before
if (libraries == null) {
//apply modifications
libs.modifyLibraries(builder.libraryModification);

//fetch the libraries and sort if a comparator was set
boolean doDefaultSort = (builder.sort && null == builder.libraryComparator && null == comparator);

libraries = libs.prepareLibraries(ctx, builder.internalLibraries, builder.excludeLibraries, builder.autoDetect, doDefaultSort);

if (comparator != null) {
Collections.sort(libraries, comparator);
} else if (builder.libraryComparator != null) {
Collections.sort(libraries, builder.libraryComparator);
}
}

//load the data for the header
if (builder.aboutShowIcon != null && (builder.aboutShowVersion != null || builder.aboutShowVersionName != null || builder.aboutShowVersionCode)) {
//get the packageManager to load and read some values :D
PackageManager pm = ctx.getPackageManager();
//get the packageName
String packageName = ctx.getPackageName();
//Try to load the applicationInfo
ApplicationInfo appInfo = null;
PackageInfo packageInfo = null;
try {
appInfo = pm.getApplicationInfo(packageName, 0);
packageInfo = pm.getPackageInfo(packageName, 0);
} catch (Exception ex) {
}

//Set the Icon or hide it
if (builder.aboutShowIcon && appInfo != null) {
icon = appInfo.loadIcon(pm);
}

//set the Version or hide it
versionName = null;
versionCode = null;
if (packageInfo != null) {
versionName = packageInfo.versionName;
versionCode = packageInfo.versionCode;
}
}
return null;
}

@Override
protected void onPostExecute(String s) {
//Add the header
if (builder.aboutShowIcon != null && (builder.aboutShowVersion != null || builder.aboutShowVersionName != null || builder.aboutShowVersionCode)) {
//add this cool thing to the headerView of our listView
mAdapter.setHeader(versionName, versionCode, icon);
}

//add the libs
mAdapter.addLibs(libraries);

//animate filling the list
if (builder.animate) {
LayoutAnimationController layoutAnimationController;

if (LibsConfiguration.getInstance().getLayoutAnimationController() == null) {
Animation fadeIn = AnimationUtils.loadAnimation(ctx, android.R.anim.slide_in_left);
fadeIn.setDuration(500);
layoutAnimationController = new LayoutAnimationController(fadeIn);
} else {
layoutAnimationController = LibsConfiguration.getInstance().getLayoutAnimationController();
}

mRecyclerView.setLayoutAnimation(layoutAnimationController);
mRecyclerView.startLayoutAnimation();
}

super.onPostExecute(s);

//forget the context
ctx = null;
}


}

public View onCreateView(Context context, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_opensource, container, false);

//allows to modify the view before creating
if (LibsConfiguration.getInstance().getUiListener() != null) {
view = LibsConfiguration.getInstance().getUiListener().preOnCreateView(view);
}

// init CardView
if (view.getId() == R.id.cardListView) {
mRecyclerView = (RecyclerView) view;
} else {
mRecyclerView = (RecyclerView) view.findViewById(R.id.cardListView);
}
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mAdapter = new LibsRecyclerViewAdapter(builder);
mRecyclerView.setAdapter(mAdapter);

//allows to modify the view after creating
if (LibsConfiguration.getInstance().getUiListener() != null) {
view = LibsConfiguration.getInstance().getUiListener().postOnCreateView(view);
}

return view;
}

public void onViewCreated(View view, Bundle savedInstanceState) {
//load the data
if (view.getContext() != null) {
//fill the fragment with the content
mLibTask = new LibraryTask(view.getContext()).execute();
}
}

public void onDestroyView() {
if (mLibTask != null) {
mLibTask.cancel(true);
mLibTask = null;
}
}

/**
* Helper to extract a boolean from a bundle or resource
*
* @param libs
* @param value
* @param resName
* @return
*/
private Boolean extractBooleanBundleOrResource(Context ctx, Libs libs, Boolean value, String resName) {
Boolean result = null;
if (value != null) {
result = value;
} else {
String descriptionShowVersion = libs.getStringResourceByName(ctx, resName);
if (!TextUtils.isEmpty(descriptionShowVersion)) {
try {
result = Boolean.parseBoolean(descriptionShowVersion);
} catch (Exception ex) {
}
}
}
return result;
}

/**
* Helper to extract a string from a bundle or resource
*
* @param libs
* @param value
* @param resName
* @return
*/
private String extractStringBundleOrResource(Context ctx, Libs libs, String value, String resName) {
String result = null;
if (value != null) {
result = value;
} else {
String descriptionShowVersion = libs.getStringResourceByName(ctx, resName);
if (!TextUtils.isEmpty(descriptionShowVersion)) {
result = descriptionShowVersion;
}
}
return result;
}
}
Loading

0 comments on commit cd13cc6

Please sign in to comment.