Code Monkey home page Code Monkey logo

buffupsdk's Introduction

Buffup SDK for Android

This SDK allows you to integrate Buffs into your sports android apps.

alt text

Installation

Gradle

Add this in your root build.gradle

    allprojects {
      repositories {
        maven { url 'https://jitpack.io' }
      }
    }

Add this in your app build.gradle

    dependencies {
      implementation 'com.github.emmanuelkehinde:BuffupSDK:1.0.0'
    }

Usage

1. The SDK exposes a custom view called BuffView, which is to be integrated into the host application using Relative Layout as parent layout.

    <com.emmanuelkehinde.buffup.view.BuffView
        android:id="@+id/buffView"    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true" />

2. In your activity/fragment, set up BuffView with the ID of the present stream you are viewing.

    buffView.setupWithStream("STREAM_ID")

3. Then, call start() function on the BuffView instance to start fetching and displaying Buffs.

    buffView.start(this)

4. Finally, initialize Buffup in your Application class by calling the initialize() function, passing in the AUTHENTICATION_KEY you obtained from Buffup.

    class App: Application() {

        override fun onCreate() {
            super.onCreate()
            
            Buffup.initialize("AUTH_KEY")
        }
    }

5. (Optional) Setup event listeners for your BuffView by calling addListener.

    buffView.addListener(object : EventListener {
        override fun onBuffDisplayed(buff: Buff) {
            super.onBuffDisplayed(buff)
            Log.d(this.javaClass.simpleName, "Buff Displayed")
        }

        override fun onBuffAnswerSelected(answer: Buff.Answer) {
            super.onBuffAnswerSelected(answer)
            Log.d(this.javaClass.simpleName, "Answer selected: ${answer.title}")            
        }

        override fun onBuffError(t: Throwable) {
            super.onBuffError(t)
            Log.d(this.javaClass.simpleName, "Error: ${t.localizedMessage}")                        
        }
    })

Customization

XML

Feel free to customize your BuffView by adding attributes in your XML as shown below.

    <com.emmanuelkehinde.buffup.view.BuffView
        android:id="@+id/buffView"    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        app:buff_author_info_text_color="@color/white"                              //default to Black
        app:buff_answer_row_background="@drawable/buff_question_answer_layout_bg"   //default to light gray with alpha
        app:buff_answer_row_text_color="@color/white"                               //default to Black 
        app:buff_author_info_background="@drawable/buff_author_layout_bg"           //default to light gray with alpha
        app:buff_question_background="@drawable/buff_question_layout_bg"            //default to Black with alpha
        app:buff_selected_answer_row_text_color="@color/colorPrimary"               //default to White
        />

Programmatically

You can also customize your BuffView programmatically as shown below.

    buffView.authorInfoBackground = ContextCompat.getDrawable(this, R.drawable.buff_author_layout_bg)
    buffView.authorInfoTextColor = ContextCompat.getColor(this, R.color.buff_text_dark) 
    buffView.questionTextColor = ContextCompat.getColor(this, R.color.white) 
    buffView.answerRowBackground = ContextCompat.getDrawable(this, R.drawable.buff_question_answer_layout_bg)
    buffView.selectedAnswerRowTextColor = ContextCompat.getColor(this, R.color.white) 

List of Attributes

Here is a table showing all the available attributes and their format.

Name format
buff_author_info_background integer
buff_author_info_text_color color
buff_close_icon integer
buff_question_background integer
buff_answer_row_background integer
buff_selected_answer_row_background integer
buff_answer_row_text_color color
buff_selected_answer_row_text_color color

Architecture

Here is a list of tools, libraries, design patterns and architecture uses in the project.

SDK

  • Kotlin - Programming Language
  • HttpUrlConnection - For Network Request
  • Couroutine - For asynchronous programming
  • MotionLayout - For Swipe Button Animation
  • Picasso - For Image loading
  • Gson - For Serialization
  • JUnit4, Mockito - For Unit Testing
  • Error Handling using throwable Exceptions

Demo App

  • Kotlin - Programming Language
  • MVVM - As app architecture
  • ViewModel - Provides data required by the fragment/activity
  • LiveData - As observable data holder for the ViewModel
  • JUnit4, Mockito - For Unit Testing
  • Expresso - For UI testing

ToDo (Future Releases)

  • Add support for more ViewGroups apart from RelativeLayout
  • Reduce the number of library dependencies used further
  • Add more customization features

Written By:

buffupsdk's People

Contributors

emmanuelkehinde avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.