Skip to content

Commit

Permalink
Merge pull request #85 from sschueller/develop
Browse files Browse the repository at this point in the history
Release v1.0.20
  • Loading branch information
sschueller committed Jan 1, 2019
2 parents d3a2e3e + 31d93ff commit cc5476e
Show file tree
Hide file tree
Showing 21 changed files with 851 additions and 97 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
### Version 1.0.20 Tag: v1.0.20 (2019-01-02)
* Added basic login framework
* AR Strings update (@rex07)

### Version 1.0.19 Tag: v1.0.19 (2018-12-31)
* Video Language Filter (@lishoujun)

Expand Down
7 changes: 5 additions & 2 deletions app/build.gradle
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "net.schueller.peertube"
minSdkVersion 21
targetSdkVersion 28
versionCode 1019
versionName "1.0.19"
versionCode 1020
versionName "1.0.20"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down Expand Up @@ -71,3 +71,6 @@ android {
}
}

dependencies {
implementation 'com.android.support.constraint:constraint-layout:+'
}
15 changes: 13 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -18,7 +18,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning"
android:name=".application.AppApplication">

<activity android:name=".activity.VideoListActivity"
android:theme="@style/AppTheme.NoActionBar"
Expand Down Expand Up @@ -48,14 +49,24 @@
android:theme="@style/AppTheme.NoActionBar"
android:label="@string/title_activity_settings" />

<activity android:name=".activity.SelectServerActivity"
android:theme="@style/AppTheme.NoActionBar"/>

<activity android:name=".activity.AccountActivity"
android:label="@string/title_activity_account"
android:theme="@style/AppTheme.NoActionBar"/>


<!-- Content provider for search suggestions -->
<provider
android:name=".provider.SearchSuggestionsProvider"
android:authorities="net.schueller.peertube.provider.SearchSuggestionsProvider"
android:enabled="true"
android:exported="false" />

<activity android:name=".activity.SelectServerActivity"/>

<service android:name=".service.VideoPlayerService" />

</application>

</manifest>
184 changes: 184 additions & 0 deletions app/src/main/java/net/schueller/peertube/activity/AccountActivity.java
@@ -0,0 +1,184 @@
/*
* Copyright 2018 Stefan Schüller <sschueller@techdroid.com>
*
* License: GPL-3.0+
* This program 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.
*
* This program 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 net.schueller.peertube.activity;

import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.IconicsDrawable;

import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper;
import net.schueller.peertube.model.Me;
import net.schueller.peertube.model.OauthClient;
import net.schueller.peertube.model.Token;
import net.schueller.peertube.network.AuthenticationService;
import net.schueller.peertube.network.GetUserService;
import net.schueller.peertube.network.RetrofitInstance;
import net.schueller.peertube.network.Session;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static net.schueller.peertube.helper.Constants.DEFAULT_THEME;
import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY;

public class AccountActivity extends AppCompatActivity {


private static final String TAG = "AccountActivity";

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_top_user, menu);

// Set an icon in the ActionBar
menu.findItem(R.id.action_logout).setIcon(
new IconicsDrawable(this, FontAwesome.Icon.faw_sign_out_alt).actionBar());

return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
// action with ID action_refresh was selected

case R.id.action_logout:
Session.getInstance().invalidate();
Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(intent);
finish();
return true;
default:
break;
}

return super.onOptionsItemSelected(item);
}

@Override
public boolean onSupportNavigateUp() {
finish(); // close this activity as oppose to navigating up

return false;
}

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

// Set theme
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
setTheme(getResources().getIdentifier(
sharedPref.getString(THEME_PREF_KEY, DEFAULT_THEME),
"style",
getPackageName())
);

setContentView(R.layout.activity_account);


// Attaching the layout to the toolbar object
Toolbar toolbar = findViewById(R.id.tool_bar_user);
// Setting toolbar as the ActionBar with setSupportActionBar() call
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(
new IconicsDrawable(this, FontAwesome.Icon.faw_chevron_left).actionBar()
);


init();
}

private void init() {
// try to get user data
getUserData();
}

private boolean getUserData() {

// TODO


String apiBaseURL = APIUrlHelper.getUrlWithVersion(this);

GetUserService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(GetUserService.class);

Call<Me> call = service.getMe();

call.enqueue(new Callback<Me>() {
@Override
public void onResponse(@NonNull Call<Me> call, @NonNull Response<Me> response) {

if (response.isSuccessful()) {

Me me = response.body();

TextView username = findViewById(R.id.account_username);
TextView email = findViewById(R.id.account_email);

username.setText(me.getUsername());
email.setText(me.getEmail());

Log.v(TAG, me.getEmail());

}


}

@Override
public void onFailure(Call<Me> call, Throwable t) {

}
});

return true;
}

@Override
protected void onResume() {
super.onResume();

init();

}
}
Expand Up @@ -18,16 +18,19 @@

package net.schueller.peertube.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.IconicsDrawable;

import net.schueller.peertube.R;
import net.schueller.peertube.helper.APIUrlHelper;
Expand All @@ -36,27 +39,23 @@
import net.schueller.peertube.network.AuthenticationService;
import net.schueller.peertube.network.RetrofitInstance;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static net.schueller.peertube.helper.Constants.DEFAULT_THEME;
import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY;

public class LoginActivity extends AppCompatActivity {

OkHttpClient client = new OkHttpClient();
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

private String TAG = "LoginActivity";


// UI references.
private AutoCompleteTextView mEmailView;
private EditText mPasswordView;
private View mProgressView;
private View mLoginFormView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -79,17 +78,30 @@ protected void onCreate(Bundle savedInstanceState) {
mEmailView = findViewById(R.id.email);
mPasswordView = findViewById(R.id.password);

// if (android.os.Build.VERSION.SDK_INT > 9) {
// StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
// StrictMode.setThreadPolicy(policy);
// }

// Attaching the layout to the toolbar object
Toolbar toolbar = findViewById(R.id.tool_bar_login);
// Setting toolbar as the ActionBar with setSupportActionBar() call
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(
new IconicsDrawable(this, FontAwesome.Icon.faw_chevron_left).actionBar()
);

}

@Override
public boolean onSupportNavigateUp() {
finish(); // close this activity as oppose to navigating up

return false;
}

private void attemptLogin() {

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

Context context = this;

// Reset errors.
mEmailView.setError(null);
Expand All @@ -106,15 +118,18 @@ private void attemptLogin() {
AuthenticationService service = RetrofitInstance.getRetrofitInstance(apiBaseURL).create(AuthenticationService.class);

Call<OauthClient> call = service.getOauthClientLocal();

call.enqueue(new Callback<OauthClient>() {
@Override
public void onResponse(@NonNull Call<OauthClient> call, @NonNull retrofit2.Response<OauthClient> response) {
public void onResponse(@NonNull Call<OauthClient> call, @NonNull Response<OauthClient> response) {

if (response.isSuccessful()) {

if (response.body() != null) {
OauthClient oauthClient = response.body();

Call<Token> call2 = service.getAuthenticationToken(
response.body().getClientId(),
response.body().getClientSecret(),
oauthClient.getClientId(),
oauthClient.getClientSecret(),
"code",
"password",
"upload",
Expand All @@ -125,13 +140,33 @@ public void onResponse(@NonNull Call<OauthClient> call, @NonNull retrofit2.Respo
@Override
public void onResponse(@NonNull Call<Token> call2, @NonNull retrofit2.Response<Token> response2) {

if (response2.body() != null) {
Log.wtf(TAG, response2.body().getAccessToken());
Log.wtf(TAG, response2.body().getExpiresIn());
Log.wtf(TAG, response2.body().getRefreshToken());
Log.wtf(TAG, response2.body().getTokenType());
if (response2.isSuccessful()) {

Token token = response2.body();

SharedPreferences.Editor editor = sharedPref.edit();

// TODO: calc expiration
//editor.putInt(getString(R.string.pref_token_expiration), token.getRefreshToken());

editor.putString(getString(R.string.pref_token_access), token.getAccessToken());
editor.putString(getString(R.string.pref_token_refresh), token.getExpiresIn());
editor.putString(getString(R.string.pref_token_type), token.getTokenType());
editor.commit();

Log.wtf(TAG, "Logged in");

Intent intent = new Intent(context, AccountActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);

finish(); // close this activity

} else {
Log.wtf(TAG, response2.toString());

Toast.makeText(LoginActivity.this, "Login Error!", Toast.LENGTH_LONG).show();

}
}

Expand Down

0 comments on commit cc5476e

Please sign in to comment.