Skip to content
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ dependencies {
compile "com.android.support:recyclerview-v7:$dependencyVersions.androidSupportLibrary"
compile "com.android.support:cardview-v7:$dependencyVersions.androidSupportLibrary"
compile "com.android.support:design:$dependencyVersions.androidSupportLibrary"
compile "com.android.support:customtabs:$dependencyVersions.androidSupportLibrary"

// Dagger 2
apt "com.squareup:javapoet:$dependencyVersions.javaPoet"
Expand Down
40 changes: 29 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,54 @@
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.futurice.freesound">
xmlns:tools="http://schemas.android.com/tools"
package="com.futurice.freesound">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".app.FreesoundApplication"
android:windowSoftInputMode="adjustResize"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".feature.home.HomeActivity"
android:label="@string/app_name">
<activity
android:name=".feature.home.HomeActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".feature.search.SearchActivity">
<!-- Have to use the full classname here otherwise get error in debug
"E/NavUtils: getParentActivityIntent: bad parentActivityName 'com.futurice.freesound.debug.feature.home.HomeActivity'" -->
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.futurice.freesound.feature.home.HomeActivity"/>

<!--
Have to use the full classname here otherwise get error in debug
"E/NavUtils: getParentActivityIntent: bad parentActivityName 'com.futurice.freesound.debug.feature.home.HomeActivity'"
-->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.futurice.freesound.feature.home.HomeActivity"/>
</activity>
<activity android:name=".feature.details.DetailsActivity"/>
<activity android:name=".feature.login.LoginActivity">

<intent-filter>
<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<data android:host="freesound"
android:scheme="com.futurice.freesound"
android:path="/app-auth"/>
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,43 @@

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.Unbinder;
import io.reactivex.disposables.CompositeDisposable;
import polanski.option.AtomicOption;
import timber.log.Timber;

import static butterknife.ButterKnife.bind;
import static com.futurice.freesound.common.utils.Preconditions.get;

public final class HomeFragment extends BindingBaseFragment<HomeFragmentComponent> {

@Nullable
@Inject
HomeFragmentViewModel homeFragmentViewModel;

@Nullable
@Inject
Picasso picasso;

@Nullable
@Inject
SchedulerProvider schedulerProvider;

@Nullable
@BindView(R.id.avatar_image)
ImageView avatarImage;

@Nullable
@BindView(R.id.username_textView)
TextView userName;

@Nullable
@BindView(R.id.about_textView)
TextView about;

@NonNull
private final AtomicOption<Unbinder> unbinder = new AtomicOption<>();
@BindView(R.id.login_button)
Button login;

@NonNull
private final DataBinder dataBinder = new DataBinder() {
Expand Down Expand Up @@ -118,19 +109,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.fragment_home, container, false);
}

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
unbinder.setIfNone(bind(this, view));
}

@Override
public void onDestroyView() {
unbinder.getAndClear()
.ifSome(Unbinder::unbind);
super.onDestroyView();
}

@Override
public void inject() {
component().inject(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2017 Futurice GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.futurice.freesound.feature.login;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import javax.inject.Inject;

import polanski.option.Option;
import polanski.option.function.Action0;

public class LoginActivity extends AppCompatActivity {

@Inject
OAuthLoginProvider oAuthLoginProvider;

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

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri uri = intent.getData();

Option.ofObj(uri.toString())
.ifSome(__ -> handleAuthCallback(uri))
.ifNone(cancelAuthRequest());

}

private Action0 cancelAuthRequest() {
oAuthLoginProvider.cancel();
}

private void handleAuthCallback(final Uri uri) {
Option<String> code = Option
.ofObj(uri.getQueryParameter(LoginConstants.CODE_AUTH_CALLBACK_QUERY_PARAMETER);
Option<String> error = Option
.ofObj(uri.getQueryParameter(LoginConstants.ERROR_AUTH_CALLBACK_QUERY_PARAMETER);
oAuthLoginProvider.handleAuthorizationResponse(code, error);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2017 Futurice GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.futurice.freesound.feature.login;

import com.futurice.freesound.common.InstantiationForbiddenError;

final class LoginConstants {

static final String CLIENT_ID_AUTH_REQUEST_QUERY_PARAMETER = "client_id";
static final String RESPONSE_TYPE_AUTH_REQUEST_QUERY_PARAMETER = "response_type";

static final String CODE_AUTH_CALLBACK_QUERY_PARAMETER = "code";
static final String ERROR_AUTH_CALLBACK_QUERY_PARAMETER = "error";

private LoginConstants() {
throw new InstantiationForbiddenError();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2017 Futurice GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.futurice.freesound.feature.login;

import com.futurice.freesound.core.BindingBaseFragment;
import com.futurice.freesound.viewmodel.DataBinder;
import com.futurice.freesound.viewmodel.ViewModel;

import android.support.annotation.NonNull;

/**
* Created by ptac on 19/02/17.
*/

public class LoginFragment extends BindingBaseFragment<> {

@NonNull
@Override
protected ViewModel viewModel() {
return null;
}

@NonNull
@Override
protected DataBinder dataBinder() {
return null;
}

@NonNull
@Override
protected Object createComponent() {
return null;
}

@Override
public void inject() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2017 Futurice GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.futurice.freesound.feature.login;

import android.app.Activity;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.customtabs.CustomTabsIntent;

import io.reactivex.Completable;
import io.reactivex.Observable;
import polanski.option.Option;

final class OAuthLoginProvider {

@NonNull
Completable attemptAuthorize(Activity fromActivity) {
return Completable.fromAction(() -> openAuthorizationUrl(fromActivity);
}

@NonNull
Completable handleAuthorizationResponse(@NonNull final Option<String> code,
@NonNull final Option<String> error) {

if (code.isSome()) {

} else if (error.isSome()) {

} else {
cancel();
}
// Either allow or denied.
// If allow then make request to API to get token.
// If deny show toast saying Login canceled?
// Need to show progress for login from the beginning (attemptAuthorize) so that it is smooth and continuous
//

}

Observable<Fetch<>>

void cancel() {

}

private void openAuthorizationUrl(Activity activity) {
Uri appAuthUrl = Uri.parse("https://www.freesound.org/apiv2/oauth2/authorize/")
.buildUpon()
.appendQueryParameter("client_id", "actualClientId")
.appendQueryParameter("response_type", "code")
.build();
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
.enableUrlBarHiding()
.build();
customTabsIntent.launchUrl(activity, appAuthUrl);
}

// Ideally expose request status as

// Data
// In Progress
// Failed

// Have "SDK" that takes Activity as parameters
// Gives callbacks which are actually redirected launched Activity
// Make these callbacks actually reactive.
}
Loading